Reputation: 97
I need help from someone with more regular expression mojo than I. I would like a somewhat efficient RE to find a string containing 8 to 12 digits with zero or more space or hyphen separators within the digits.
I can brute force it but I’m hoping for something more elegant.
Added:
Basically anything like:
123-456-78, 1-2-3-4-5-6-7-8-9-0-1-2, 12345678, 12345 67890
But I don’t want:
0-123456789012, 012345 6789012
(Sorry, editing on iPad)
Upvotes: 0
Views: 97
Reputation: 306
You can try this which looks for a sequence of 8-12 digits with optional space or hyphen:
^(\d[\s-]?){8,12}$
Upvotes: 1