simple numeric validation in jquery for input -
can me simple jquery numeric validation?
<input type="text" name="yourphone" id="yourphone" required style="border-radius:6px; border:1px solid #ccc; width:300px; height:25px;" /> <input type="submit" value="send inquiry" class="button" id="mysubmitbutton" />
you can change input type number <input type="number"...
(although not browsers support html5 input types).
or can use this:
$('#myform').on('submit', function(){ var value = $('#yourphone').val() return $.isnumeric(value); });
but phone numbers can complex, not numbers.
in case user uses +
(
)
-
.
,
can use this:
(demo)
$('#myform').on('submit', function(){ var value = $('#yourphone').val() var regex = new regexp(/^\+?[0-9(),.-]+$/); if(value.match(regex)) {return true;} return false; });
Comments
Post a Comment