views:

220

answers:

3

I am trying to make a height (person height) and weight validation.

Height should look something like this: 5'11"

Anything in any other different format should show up as wrong.

What should I use for ValidationExpression?

and onee more question "[10-200].(1[0-1]|\d)" is this correct for weight validation

+2  A: 

A simple regex for sensible height in feet/inches would be:

[2-7]'(1[01]|\d)(''|")

For an ASP.NET ValidationExpression, it would be something like:

<asp:RegularExpressionValidator id="myHeightRegex" runat="server"
                                ControlToValidate="txtName"
                                ValidationExpression="[2-7]'(1[0-1]|\d)(''|\")"
                                ErrorMessage="Invalid Height" Display="Dynamic" />
Max Shawabkeh
"[10-200].(1[0-1]|\d)" is this correct for weight validation
Not quite - remember we're dealing with characters, not integer values here. You could use: `([4-9]\d|[1-3]\d\d)\s*lb` to allow 40-399 lbs.
Max Shawabkeh
+1  A: 

Switch to metric :-)

180 cm or even 1803 mm if you want accuracy

Much simpler and compatible with the rest of the ENTIRE world

TFD
-1 where's the fun in that! BTW was that metric or imperial -1?
TFD
+1  A: 

why not just use two fields and make sure the values are both integers withing a certain range (range validator) (inches field could be blank) - then you don't have to mess with regular expressions all day.

FiveTools