Since any of the digits can be zero, but not all at once, you should treat the one case where they are all zero as a single, special case.
You are checking for two digits (\d{2}
), then an optional hyphen (-?
), then another two digits (\d{2}
) and another optional hyphen (-?
), before another two digits (\d{2}
).
Putting this together gives \d{2}-?\d{2}-?\d{2}
, but you can simplify this further:
(\d{2}-?){2}\d{2}
You then use the following pseudocode to match the format but not 000000
or 00-00-00
:
if (string.match("/(\d{2}-?){2}\d{2}/") && !string.match("/(00-?){2}00/"))
//then it's a valid code, you could also use (0{2}-?){2}0{2} to check zeros
You may wish to add the string anchors ^
(start) and $
(end) to check the entire string.