javascript - Regex for 8 digit phone number (Singapore number length) -
i'm trying validate phone address text field. can provide me simple regex either validate numeric digits or specific 8 digit regex?
much thanks!
$('#phone').on('input', function() { var input = $( ); var regex = /* regex needed here */ var is_phone = regex.test(input.val()); if (is_phone){input.removeclass("invalid").addclass("valid");} else {input.removeclass("valid").addclass("invalid");} });
it allow 0-9 numbers , 8 digits. try this:
var regex = '/^[0-9]{1,8}$/'; // if want min 1 , max 8 numbers var regex = '/^[0-9]{8}$/'; // if want exact 8 numbers
Comments
Post a Comment