-6

Please anyone help me to frame a regular expression to validate a mobile number in javascript. The criteria is i have to allow + symbol , - symbol , digits , space , open brace ( and close brace ( Eg: +0 (080) - 90343534554

Anita
  • 185
  • 1
  • 6
  • 24
  • 1
    Have you tried anything so far? – Jerry Sep 16 '13 at 10:16
  • I tried this /^[0-9 ()-/+/(/)]+$/ – Anita Sep 16 '13 at 10:17
  • possible duplicate of [A comprehensive regex for phone number validation](http://stackoverflow.com/questions/123559/a-comprehensive-regex-for-phone-number-validation) – Artem Koshelev Sep 16 '13 at 10:19
  • You use backslash \ to escape and don't put the `-` (hyphen) in the middle. Put it at the end of the character class or at the beginning. And last, you don't need to escape metacharacters except backslash. Are all the phone numbers in that format? – Jerry Sep 16 '13 at 10:22
  • this one could be useful : http://stackoverflow.com/questions/8443911/regular-expression-matching-phone-number-in-javascript – walid Sep 16 '13 at 10:23

1 Answers1

2

If there is no restriction on the position or count of of special characters then you can use below regex:

^[+\-\d\s\(\)]+$

However according to standards, I would suggest to use :

^\+?[\d\s]+(\-([\d\s]|[\s]*(\([\d]+\)[\s]*))+)+$
Adarsh Kumar
  • 1,134
  • 7
  • 21