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.
encoredatasAsked:
Who is Participating?
 
fsze88Connect With a Mentor Commented:

<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){
  return (pattern.test(formObj.personheight.value));
}
</script>

Open in new window

0
 
fsze88Commented:
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

0
 
encoredatasAuthor Commented:
Thanks!  I will accept your solution. I just realized how do I make the inches part of the height optional all together. ie   5'
0
 
fsze88Commented:
or
var pattern=new RegExp("^[0-9]+\'([ ]?[0-9]{1,2}[\"]?|)$");
if you didn't like space at tail
0
 
encoredatasAuthor Commented:
Thanks fsze88 so much, I would have never figured this out.
0
All Courses

From novice to tech pro — start learning today.