I need to validate phone number by regular expression. The phone number should
I come up with /(09|9|8869|+8869)[0-9]{8}$/g
. I test with +8869900000000 and expect it will not match but actually it passed Could you help me to address the regex problem? And how do I fix it?
You can use this regex: /^(0?9|\\+?8869)\\d{8}$/
The group (0?9|+?8869) is for your starting condition where 0 is optional before 9 and + is optional before 8869.
The regex you are looking for is : ^(([0]?9)|([+]?8869))[0-9]{8}$
Note the way round brackets used to determine the conditions. We need to match within any of the 2 subsets and then precede it 8 digits.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.