We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

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

on
Medium Priority
3,254 Views
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.
Comment
Watch Question

## View Solution Only

CERTIFIED EXPERT

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

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'
CERTIFIED EXPERT
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>
``````

Not the solution you were looking for? Getting a personalized solution is easy.

CERTIFIED EXPERT

Commented:
or
var pattern=new RegExp("^[0-9]+\'([ ]?[0-9]{1,2}[\"]?|)\$");
if you didn't like space at tail

Commented:
Thanks fsze88 so much, I would have never figured this out.
##### Thanks for using Experts Exchange.

• View three pieces of content (articles, solutions, posts, and videos)
• Ask the experts questions (counted toward content limit)
• Customize your dashboard and profile