-1

I'm trying to write a regular expression for an indian mobile number with +91 as optional before the number

The regEx that I have written is below:

^[\+91]?[7-9][0-9]{9}$

This isn't working properly, please help.

Harish
  • 1,193
  • 6
  • 22
  • 45
  • Can you post an example string that fails this test? – Mohit Bhardwaj May 12 '17 at 06:20
  • Check `webx` answer here => http://stackoverflow.com/questions/3813195/regular-expression-for-indian-mobile-numbers – David R May 12 '17 at 06:21
  • Probably your issue is related to the `[\+91]` part. If so, try using `[(\+91)]` instead. – Mohit Bhardwaj May 12 '17 at 06:23
  • How is it "not working properly"? You need to read up on the meaning of a character set or class (`[]`). `[/+91]` does **not** mean to match `+91`. You could also search for other answers on SO, of which there are more than one. –  May 12 '17 at 06:37

1 Answers1

0

I think this should work. I've tested it on https://regex101.com/

 /^((\+91?)|\+)?[7-9][0-9]{9}$/
  • 1
    This will match `1234567890` which is not a valid number. –  May 12 '17 at 06:38
  • Thanks for reminding me about using groups. I have edited your regex and here's what I have written which is working perfectly /^((\+91?)|\+)?[7-9][0-9]{9}$/; – Harish May 12 '17 at 06:48