javascript - validation for only integers in text box -


this question has answer here:

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

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -