PDA

View Full Version : Regular Expressions - ASP.Net


gtsikes
02-21-2005, 06:41 PM
Hi,

I am trying to control the input style of a textbox on a form using a regular expression validator. This is my first try at a custom expression. I want to control the input format for use in a dropdown box later. The format describes the size of an envelope blank. Such as 10-15/16 X 11-7/8 or 10 X 13. 39 X 39 is the largest size I will allow. Each fraction must be the lowest denominator in 16th's, 8th's, 4th's or half's. Fractions are preceded directly by a dash. Width and height are separated by a space upper-case X space. The expression I created works, but seems long. Can this be done more efficiently?

([1-3]{1}[0-9]{1}|[1-9]{1})(-1[135]{1}/16|-[13579]{1}/16|-[1357]{1}/8|-[13]{1}/4|-1/2)?( X )([1-3]{1}[0-9]{1}|[1-9]{1})(-1[135]{1}/16|-[13579]{1}/16|-[1357]{1}/8|-[13]{1}/4|-1/2)?

My expression reads;

([1-3]{1}[0-9]{1}|[1-9]{1})
One instance of 1 to 3 followed by one instance of 0 to 9 or one instance of 0 to 9.

(-1[135]{1}/16|-[13579]{1}/16|-[1357]{1}/8|-[13]{1}/4|-1/2)?
Zero or one occurance of
Dash and one instance of 1 and one instance 1 or 3 or 5 then /16 or
Dash and one instance 1 or 3 or 5 or 5 or 7 or 9 then /16 or
Dash and one instance 1 or 3 or 5 or 5 or 7 then /8 or
Dash and one instance 1 or 3 then /4 or
Dash and 1/2

( X )
space uppercase X space

repeat first two sections of the expression.

Jerry Sikes