Reputation: 9485
I wish to be able to match those values.
AND
It seem there is no AND operators i tried this..
^(?=[0-9]{8}|[0-9]{11})(?=[^0]{8}|[^0]{11})$
But it doesn't seem to work at all. Any ideas ?
Upvotes: 0
Views: 84
Reputation: 11132
This regex should work:
^(?!0{8}$)(?!0{11}$)(?:\d{8}|\d{11})$
Online explanation and demonstration: http://regex101.com/r/sH1nZ5
Alternatively, you could use
^(?!0{8}$)(?!0{11}$)\d{8}(?:\d{3})?$
which does the exact same thing: http://regex101.com/r/iX2xM2
Upvotes: 1
Reputation:
Or, it could be written this way
# ^(?=.{8}(?:.{3})?$)[1-9]+$
^
(?=
.{8}
(?: .{3} )?
$
)
[1-9]+
$
Upvotes: 0
Reputation: 4896
You might be looking for the union of two sets and the OR |
operator if you want to match both sets.
^(?=[0-9]{8}|[0-9]{11})|(?=[^0]{8}|[^0]{11})$
If you simply want to match a string that is not 0
8 or 11 times, followed by 0-9
8 or 11 times, just put them in order.
Upvotes: 1