Link to home
Start Free TrialLog in
Avatar of Martin Davis
Martin DavisFlag for United States of America

asked on

Regular Expression for Height of a Person to be entered in various formats

I need a regular expression to allow a person to enter their height in the following format either
5'10  or  5'10" making the quotation marks optional for the inches. There also could be a space between the feet and inches like 5' 10 or 5' 10".
thanks for the help in advance.
Avatar of Kin Fat SZE
Kin Fat SZE
Flag of Hong Kong image

tested on ie6,ff3
<form onsubmit="return validateHeight(this);">
<input type="text" name="personheight">
<input type="submit" value="test height">
</form>
 
 
<script language="javascript">
var pattern=new RegExp("^[0-9]+\'[ ]?[0-9]{1,2}[\"]?$");
 
function validateHeight(formObj){
//  alert(formObj.personheight.value);
  return (pattern.test(formObj.personheight.value));
//return false;
}
</script>

Open in new window

Avatar of Martin Davis

ASKER

Thanks!  I will accept your solution. I just realized how do I make the inches part of the height optional all together. ie   5'
ASKER CERTIFIED SOLUTION
Avatar of Kin Fat SZE
Kin Fat SZE
Flag of Hong Kong image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or
var pattern=new RegExp("^[0-9]+\'([ ]?[0-9]{1,2}[\"]?|)$");
if you didn't like space at tail
Thanks fsze88 so much, I would have never figured this out.