Reputation: 5827
I want to accept a number if it is length of 7, 9 or 10. Is there any short version of it ?
I can limit max and min length like below , but is there any way to make this range fixed by specified numbers.
[\d]{7,10}$
Upvotes: 0
Views: 128
Reputation: 65176
Well, you can get rid of the []
but that's about as short as it gets.
^(\d{7}|\d{9}|\d{10})$
Alternatively you could do this which does save a few characters but I think the first one is easier to read:
^\d{7}(\d{2,3})?$
Upvotes: 5