Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript regex to match a person's height

I need a javascript regex pattern to match a person's height to check if the input is valid. Here are some sample input:

5' 9"

6'

5'8"

Any ideas?


1 Answers

If you want to make sure that no one mucks around with it, you could limit it to sensible ranges, eg: 3' to 7'11''

/^(3-7)'(?:\s*(?:1[01]|0-9)(''|"))?$/

I always thought that the "inches" mark was a double quote ("), compared to VonC's answer where he put it as two single quotes (''), so this regex takes both into consideration.

like image 182
nickf Avatar answered Apr 10 '26 18:04

nickf