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

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

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -