How to write XPath expression for #input. I'm trying this
expression:
//input[#input='onSearchInput'].
This expression not found.
HTML input tag:
<input type="text" class="input" #input="onSearchInput" placeholder="Word search" style="">
Your markup is not well-formed due to the # character in #input. Remove the # character if you want to use XML-based tools such as XPath.
See also Is the at-sign (#) a valid HTML/XML tag character?
Related
This is my Regex:
pattern="[^\!\#\$\%\^\&\*\'\|\"]{8}"
pattern="[^!#$%^&*'|"]{8}"
How is this invalid in my HTML input tag? I want this symbols to be restricted in my textbox
<input placeholder="Something" type="text" required autofocus ng-model="someData" pattern="[^\!\#\$\%\^\&\*\'\|\"]{8}">
I think it should be pattern=\"[^!#$%^&*'|"]{8}\"
You should escape literal double quote outside [] instead of inside.
Demo: https://regex101.com/r/uP5pC6/1
How do I validate for a pattern like this...
(562) 810-5566 or (714) 433-4434
Note that it will contain parenthesis and a space.
My current input control looks like this:
<input type="tel" data-tel-msg="Invalid Phone Number!" class="k-textbox" pattern="^\d{3}-\d{3}-\d{4}$" required />
I'm aware the current pattern matches 3334445555, but it's not what I'm looking for, when I tried adding parenthesis the JavaScript console just gave an error incorrect regex syntax.
Also as a bonus, if you know how to get it to display a custom error message that would help also. Currently my data-tel-msg is not working.
You can use the following code:
input:valid {
color: green;
}
input:invalid {
color: red;
}
<form name="form1">
<input value="(555) 324-5643" type="tel" title="Invalid Phone Number!" class="k-textbox" pattern="[(][0-9]{3}[)] [0-9]{3}-[0-9]{4}" required />
<input type="Submit"/>
</form>
The regex \(\d{3}\)\s\d{3}-\d{4} matches strings in (###) ###-#### format since the HTML5 pattern is anchored (to the start and end of string) by default.
The title attribute allows showing error text.
If the backslashes are lost in your environment, just double them, or replace \d with [0-9]. To match a literal \( you can also use a character class: [(] (same for ): [)]). Inside a character class, these ( and ) lose their "special" grouping meaning.
Here I have a HTML5 input.....
<input type="number" pattern="\d{10}" data-pattern-msg="enter a value according to the pattern" />
But this is not validating this pattern ......
What is the reason for this ??
Maintainer of the W3C HTML Checker (validator) here. The reason the checker is emitting an error for your example is that the HTML spec doesn’t allow the pattern attribute to be specified for <input type=number> elements; see the The following content attributes must not be specified and do not apply to the element list in the Bookkeeping details section of the section on the HTML spec on <input type=number>.
And I’m not sure that most browsers support using placeholder with <input type=number>.
This is wrong type = "number" change to type="text" and try
<input type="text" pattern="\d{10}" data-pattern-msg="enter a value according to the pattern" title="only number" />
Definition and Usage
The pattern attribute specifies a regular expression that the element's value is checked against.
Note: The pattern attribute works with the following input types: text, search, url, tel, email, and password.
Tip: Use the global title attribute to describe the pattern to help the user.
Here's some code:
<form>
<input type="text" name="Title" pattern="[a-zA-Z0-9`\~\!\#\#\$\%\^\&\*\(\)\-\\\\=\+\{\}\[\]\']{2,40}" required>
<input type="submit">
</form>
I would like to add quotes to the allowed in the regex expression, however \" does not work and " does not work, either...
So I can just replace the quotes with \x22. Now I'll have to figure out which one to use (I can instead disallow instead of allow, or use \x22 in place of the quotes). I can't remember all of the original reasons I chose to specifically allow, so I might stick with replacing it with \x22, since it's so simple and less modifying.
I use PHP to get radio button values from an HTML page. My HTML looks like this:
<input type="radio" name="1.1" value="yes">
<input type="radio" name="1.1" value="no">
<input type="radio" name="1" value="yes">
<input type="radio" name="1" value="no">
The result is that $_POST['1'] returns a value, but $_POST['1.1'] returns nothing. I checked the HTML 4 specifications, say value for the name attribute only starts with a letter, but 1 is not a letter. How come it gets returned while 1.1 does not? Or is there some other magic happening here? I use the latest version of Chrome.
By HTML rules, the name attribute may have any value: it is declared with CDATA type. Do not confuse this attribute with the references to attributes declared as having NAME type. See 17.4 The INPUT element, name = cdata [CI].
In the use of $POST[...] in PHP, you need to note this PHP rule: “Dots and spaces in variable names are converted to underscores. For example <input name="a.b" /> becomes $_REQUEST["a_b"].” See Variables From External Sources.
So $_POST['1'] should work as is and does work, but instead of $_POST['1.1'] you need to write $_POST['1_1'].
Try substituting the period for something else like a hyphen. In both the form and the PHP code. Periods are generally used for a . in the extension name.
When it comes to key names for parameters in either GET or POST headers, you want to only use alphanumeric characters, with some special characters generally. Such as hyphens, underscores, etc. You can always do a URL encode if you need to as well.
You should name your input items with text, not numbers. They should not contain any characters such as ., ,, !, and ?. This can cause problems. For more information submitting the data, go to PHP and HTML Radio Buttons