Question

I am trying to write in java script to exclude invalid mobile numbers that are entered into the SQL database. i currently have the regex function within my script however it cant pick up brackets(), resulting in numbers such as (123) 456789 not being included.

Is there any extension to the regex i could use to include brackets?

No correct solution

OTHER TIPS

There is a free google API that can validate numbers for you, even tell you the country code etc. https://code.google.com/p/libphonenumber/

Never tried it, but I evaluated it once for another project I worked on.

This is Java, not JS, but still you may consider moving your validation logic to a Java servlet and invoke using an AJAX call.

1) This would expect atleast one white space character after parenthesis

/\(\d{3}\)\s+\d{6}/

Or

/\(\d+\)\s+\d+/ //in case of digit not specified.

2) This would match with or without space

/\(\d{3}\)\s*\d{6}/

//eg:-
// (123)456789
// (123) 456789
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top