I'm trying to get a regex that will validate the following formats:
234-567-8901
1-234-567-8901
I have tried various examples, but not sure how to get the one that will take into account the possible 1- at the begging and still inforce the 234-567-8901.
Rules are, any digit, 2 or 3 dashes, if 3 dashes then 11 numberes, if 2 dashes then 10 numbers.
^[0-9-]*$
^[\d-]+$
^[\d-]+$
Answer
You can use:
^(1-)?\d{3}-\d{3}-\d{4}$
No comments:
Post a Comment