Home > Software design >  Not able to differentiate between 91 and 19 using REGEX
Not able to differentiate between 91 and 19 using REGEX

Time:02-04

I'm using below REGEX for Indian number formatting like 919639458752

[91]{2}[1-9]{1}[0-9]{9}

but what's happening is it's accepting 19 as well i.e. 199639458752 which is absolutely wrong. Please suggest

CodePudding user response:

Note that [91]{2} means two digits which are either 1 or 9. If you intend to match Indian phone numbers starting with country code 91, then add boundary markers to your regex pattern:

^91[1-9][0-9]{9}$

CodePudding user response:

This should do:

91[1-9]{1}[0-9]{9}

If that doesn't meet your need, please give more details on what you exactly want :)

  •  Tags:  
  • Related