Validating cell no using regular expression - html

I am trying to validate cell no using html. I've write the following regular expression but its not working. Can anybody please help me?
<input required="required" name="txtcellno" id="txtcellno" type="text" value="" pattern="/^+[9][2][0-9]{1,10}$/" placeholder="+92xxxxxxxxxx" />

+ has special meaning, and should be escaped (\+).
Input patterns must match the whole string, so ^ and $ are unnecessary.
Input patterns must not be wrapped in /.../
Given all that, and simplifying [9][2] to 92:
<input required="required" name="txtcellno" id="txtcellno" type="text"
value=""
pattern="\+92[0-9]{1,10}"
placeholder="+92xxxxxxxxxx" />
Example: http://codepen.io/paulroub/pen/jELiI

Related

Pattern attribute not working as expected?

So I'm trying to make a form for my assignment, and I am using the pattern attribute in html so only certain characters are required to be typed on the text box. But for some reason, the form is saying using that I'm using an incorrect format even though I made my pattern attribute that way.
Here's an example of the code and a picture of the problem.
<form>
<label for="mnumber">Mobile Number:</label>
<input type="text" required id="mnumber" pattern="[0-9]"><br><br>
<input type="submit" value="submit">
</form>
You did write:
pattern="[0-9]"
You are asking for only one number. You just forget to add '+' to accept more than one number. I guess what you are searching for is this:
pattern="[0-9]+"
pattern="[0-9]"
allows for only a single number character to validate (and be submitted). If you want to allow more than one character, here's your options:
One or more numbers:
pattern="[0-9]+"
Zero or more numbers:
pattern="[0-9]*"
One to three numbers:
pattern="[0-9]{1,3}"
you just need to change type="text" to type="number"

HTML form - input validation with Alphanumeric with symbols ()._-‘ only

I want to validate below input with Alphanumeric and ()._-‘ symbol only.
<input type="text" name="companyName" value="" pattern="[A-Za-z0-9()._-‘]+" title="Alphanumeric with symbols ()._-‘ only" required> </p>
But, when I try the input, only ._‘ can be used, ()- are not working.
You need to escape those characters. They have significance in RegEx and aren't treated as part of the expression. Try the following: [A-Za-z0-9\(\)._\-‘]+
Works fine for me, with the exception of the '-' which probably needs to be first:
[-A-Za-z0-9()._‘]
Try the code below. I don't know why, but the order for the pattern attribute matters.
<form>
<input type="text" name="companyName" value="" pattern="[A-Za-z0-9()_.'-]+" title="Alphanumeric with symbols ()._-‘ only" required>
<input type="submit">
</form>

HTML form validation with the “pattern” attribute

I am trying to come up with a valid pattern for an HTML form. I would like to allow *#student.*.edu.vn
This is my code:
<input
type="text"
name="mail"
pattern="([a-z]|[0-9])+(#{1})+(student)+(.)+[a-z]+(.edu.vn)"
/>
It does not work as I would like. What I am doing wrong?
The pattern (regular expression) is slightly wrong as you haven't escaped all your special characters such as the . and have some unnecessary parts within it. Try using the following slightly modified pattern instead:
([a-z]|[0-9])+#student\.[a-z]+\.edu\.vn
<form>
<input type="text" name="mail" pattern="([a-z]|[0-9])+#student\.[a-z]+\.edu\.vn" />
<input type="submit">
</form>
Note: Make sure that you also do validation on the server-side as anyone entering values into a form can remove the pattern to bypass this check.
I came up with this solution which is slightly more easy to read and is less strict (which is a good thing because e-mail addresses can contain a lot more characters than just lowercase alpha-numeric ones. Don't forget to do proper validation on the backend using an e-mail validator.
<form>
<input
type="text"
name="mail"
pattern=".+#student\..+\.edu.vn"
/>
<input type="submit">
</form>

removing char in string after space

I'm having problem with that java framework seems to remove the content of a string after a space character.
code example
<input type="text" name="txtName" size="25" value=<%=Name%>>
If Name is equal to "This is my name" the input text only show "This".
I'm guessing this is to avoid xss problems but I need to be able to use strings that contain space so how do I get around this? (i'm using tomcat)
You need to add quotes around the value of your value attribute.
This is always the case in HTML when attribute values contain spaces.
(ie it has nothing to do with Java)
It should look like this:
<input type="text" name="txtName" size="25" value="<%= Name %>">
This will do... value="<%=Name%>"
<input type="text" name="txtName" size="25" value="<%=Name%>">

Match a string but not a blank space using HTML5 input pattern

I'm using the HTML5 pattern attribute in an <input> to return a match for a specific string: 'felfogtam'
My current markup is:
<input type="text" class="input input-small" pattern="felfogtam">
It does work, but the input is still valid if the field is empty. How can I change the regular expression to not allow a blank field?
Add the required attribute
<input type="text" class="input input-small" pattern="felfogtam" required>
http://jsfiddle.net/bJU2D/