[thelist] regex: 0-1 range VS optional
Brian Cummiskey
brian at hondaswap.com
Thu Feb 15 12:29:09 CST 2007
Both of these seem to work for all my cases, but i'm not sure which is
the better version to use.
I need to validate some item numbers, which come in one of 3 formats:
normal: 123456 (1 to 7 digits in length)
drop ship: D123456 (gets a D prefix)
child item: 123456A (gets a single letter suffix)
and there can also be drop ship child items, as in D123456A
I've come up with two versions which both appear to negate bad entries
correctly, but i'm not sure which is considered more proper:
^(d|D)?[0-9]{1,7}([a-zA-Z]{0,1})$
^(d|D)?[0-9]{1,7}([a-zA-Z]?){1}$
the first allows either 0 or 1 letters at the end, where as the second
allows 1 letter, optionally.
More information about the thelist
mailing list