REgular expression validation

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using a RegularExpressionValidator to validate against a range on
specific values and it is behaving strangely. My validation expression is as
follows

^001|100|101|101D|102|103|103D|110|110D|111|112|113|114|114D|115|115D|116|117|117D|118|118D|119|120|120D|121|124|126|126D|127|127D|128|128D|129|129D|130|130D|131|131D|132|132D|600|610|611|612|613|613D|616|661|711|712|712D|118D$

Which are a series of valid product codes. It validates correctly against
all of the codes that are just numbers, but it does not validate against the
codes that contain a D at the end.

e.g.

It is happy with 001, 100 or 101 but it says 104 is invalid, which is as it
should be. Byt when i enter 110D then it says it is not valid even though it
is in the validation expresion.
 
Regular Expressions consume the strings they match, character by character.
Since you put "110" before "110D", "110" will always be consumed as a match
before the opportunity to find the "D" occurs. To fix, this, simply reverse
the order of items which contain other items. For example:

110|110D should be 110D|110
118|118D should be 118D|118

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.
 
Back
Top