javascript - validation for only integers in text box -
this question has answer here:
- html5: number input type takes integers? 18 answers
when using
<input type="number" name="phoneno" class="required number" minlength="10" maxlength="15" id="ph" />
it accepts floating point number also. how use prevent text box accept other integers?
since seem trying phone number, not generic number, want use tel
type of input
:
<input type="tel" name="phoneno" class="required number" maxlength="15" pattern="\d{10}" id="ph" />
see msdn on <input>
, attributes. i’ve removed minlength
, since it’s not valid attribute, pattern
attribute’s regex requires 10 characters. can change regex if want more flexible in formats of phone numbers allow – instance, use \d{10}|\d{3}-\d{3}-\d{4}
.
the pattern
attribute necessary verify text looks phone number. browser little validation of contents of tel
inputs default; displays keyboard numbers mobile browsers. can write javascript regular expression in pattern
attribute use in validation (as msdn page explains).
Comments
Post a Comment