Regex in javascript - should not allow consecutive parenthesis , consecutive + sign and consecutive -sign -
i need validate phone number can any format. should not allow consecutive hyphens, parenthesis , + signs. in addition no special characters , alphabets should not allowed. not @ regex.
allowed be:
single -, ( , ), (), + , spaces.
i have tried following regex
(?!-)(?!.*--)(([0-9-,(),+]{0,25}))
through able restrict consecutive hyphens.
can on this?
eg:
+765766-8776(090) --> valid format 7-(98665 --> valid 123456789098880998 --> valid 85786 87787 --> valid +165667687777878(989)--> valid +1 97877-88888 (090) --> valid ----()90 --> invalid consecutive hyphens ffgffgtgf98- --> invalid characters there #$%%5 --> invalid special characters there +++++++++898988++++++++76768 -->invalid consecutive plus sign 989(((090)))) -->invalid consecutive parenthesis
/^(?:(?:([-()+ ])(?!\1))|\d)+$/
- start of string
- either of these:
- special character, not followed same character
- a number
- (* repeat many times needed)
- end of string
Comments
Post a Comment