Thursday, 28 July 2016

Regex to validate International phone numbers.

International phone numbers validate regex:-


/^\s*(?:\+?(\d{1,3}))??[(]{0,1}[0-9]{3}[)]{0,1}[-\s.]{0,1}[0-9]{3}[-\s.]{0,1}[0-9]{4}$/;

1234567890
+11234567890
+1(123) 456-7890
(123) 456-7890
123-456-7890
+1123-456-7890
123.456.7890
+1123.456.7890
(734) 555.1212
+1(734) 555.1212


Regex to validate only 10 digits:

/^\s*[(]{0,1}[0-9]{3}[)]{0,1}[-\s.]{0,1}[0-9]{3}[-\s.]{0,1}[0-9]{4}$/

This will validate only number of 10 digits:
1234567890

No comments:

Post a Comment