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

encoredatas
encoredatas asked
on
Medium Priority
3,254 Views
Last Modified: 2013-11-05
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

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

Open in new window

Author

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>

Open in new window

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

Ask the Experts
CERTIFIED EXPERT

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

Author

Commented:
Thanks fsze88 so much, I would have never figured this out.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

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

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.