javascript - Phone number validation for specific format -


i have below regex check valid phone number in different formats, support arabic numbers:

/^(\+?\s{0,2}([0-9\u0660-\u0669]{1,3}))?[-,.\s]{0,2}\(?[0-9\u0660-\u0669]{1,5}\)?[-,.\s]{0,2}[0-9\u0660-\u0669]{1,5}[-,.\s]{0,2}[0-9\u0660-\u0669]{1,6}\s{0,2}\+?/ 

but returning false 1 of valid number +(91)-20-xxxxxxxx

the first optional group matches + needs optional ( , ):

^(\+?\(?\s{0,2}[0-9\u0660-\u0669]{1,3}\)?)?[-,.\s]{0,2}\(?[0-9\u0660-\u0669]{1,5}\)?[-,.\s]{0,2}[0-9\u0660-\u0669]{1,5}[-,.\s]{0,2}[0-9\u0660-\u0669]{1,6}\s{0,2}\+?      ^^^                              ^^^ 

see regex demo

note might re-check pattern, trailing \+? looks rather suspicious, , there no $ (end of string anchor) @ end of pattern (if plan match whole string, need anchor).


Comments

Popular posts from this blog

many to many - Django Rest Framework ManyToMany filter multiple values -

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

Java Entity Manager - JSON reader was expecting a value but found 'db' -