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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -