0
Regular Expression for number only
I use [0-9] expression to validate text field have number only. If you write abc 900 so it gives error, but i you write 900 abc , it gives no error. What's correct regular expression for number only Please help.
4 Réponses
+ 5
What message "never remove"?
How do you handling your input validation? in which context?
If you are validating inputs from html <input> through the attribute pattern, you can do the behavior you describe: show/hide an error message... suppose you have:
<label>Choose a number:</label><br>
<input type="text" pattern="^\d+quot;><br>
<label>error message</label>
input+br+label {
opacity:0;
color:red;
}
input:invalid+br+label {
opacity:1;
}
However, you can use the <input type="number"> for this special case ;)
... If you handle regexp in html form context... but you don't specify :P
+ 2
^\d+$ or ^[0-9]$
0
Thank you its work with ^[0-9]*$
- 1
IIya, now it shows validation message but if user correct it the error message never remove