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
Post a Comment