Invalid regular expression HTML Pattern - html

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

Related

How to write XPath expression with #attribute

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?

Preventing leading white space in input field pattern

Problem
I'm trying to prevent leading whitespace from being used in an input whether through spaces or tabs by using a pattern, but I'm having issues with this regular expression ^(?!\s)([a-zA-Z0-9 _.'"()!?&#]){1,}$, which I think is because I might not be escaping properly because of the quotation marks?
Ultimately, I want to make sure the input takes at least one character, but none of those characters be leading white space at the beginning of the query.
Invalid inputs
_This is a query
__This is a query
Valid inputs
This is a good input
abc
123
a
index.html
<form action="{% url 'master_search' %}" method="GET">
<i class="fa fa-search search-icon-drilldown" aria-hidden="true"></i>
<input type="text" class="nav__search--agency form-control inline" name="q" value="" placeholder="Search by employee name" pattern="^(?!\s)([a-zA-Z0-9 _.'"()!?&#]){1,}$" required>
</form>
Hm. If you want to allow everything that starts with a letter or number,
pattern="^[a-zA-Z1-9].*"
should do the job
You could also negate a range by doing
^[^\s]+.*$
which will match a line with a starting character that is not white space.
This is A pattern , which is uses to input type in html, but for name validation I have been analysise the pattern
pattern="^(?!\s)[a-zA-Z ]{1,}$" and I used the title (title="Request Format:Not valid numeric val & special character. Only Character") for Requested pattern form in my input type html form where type="name"

I would like to add quotes to a regex expression in an HTML tag

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 &quot 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.

Why is my hidden HTML form field showing up?

I'm trying to put some data in a hidden form field for a POST. But the field is showing up on my Web page. There are no styles or style sheet. Here's how the fields are defined. Any ideas?
<form action="GetUserPics.php" method="post">
<input type=”hidden” name=”picIndex” value="WHAT?">
<input type="submit" value="previous">
</form>
You are using non-standard quotation marks for your attributes on that field. HTML is interpreting those quotes as part of the attribute's value, as in:
<input type="”hidden”" name="”picIndex”" value="WHAT?">
Since ”hidden” is not a valid input type, it's reverting to text.
Because you're not using ASCII quotes, you're using some sort of weird slanty quotes that the HTML is trying to use as the type (and thus it will fall back to text). Interestingly, you're not using them to print the value, which incidentally hides your mistake.
<input type=”hidden” name=”picIndex” value="WHAT?">
Those are not regular double quotes. Try
<input type="hidden" name="picIndex" value="WHAT?">
Can you replace your hidden type input with this:
<input type="hidden" name="picIndex" value="WHAT?"/>

Are apostrophes valid containers for HTML element attribute values?

Usually HTML element attribute values are marked with a quotation mark, like
<input type="hidden" value="test" />
Sometimes, however, you see code like
<input type='hidden' value='test' />
Is it valid HTML and can it cause any problems? What about mixing the two, like
<input type='hidden' value="test">
?
The linked question from James Allardice's comment to my original question lead me to the answer: yes, apostrophes are valid containers for HTML element attribute values.
Specification: On SGML and HTML
By default, SGML requires that all attribute values be delimited using either double quotation marks (ASCII decimal 34) or single quotation marks (ASCII decimal 39). Single quote marks can be included within the attribute value when the value is delimited by double quote marks, and vice versa.