0

How can you prefill an input box with 0'00" Then as the user starts typing it prefills in those 0's? like 12'02". I want the left side of the " ' " to be able to reach 2000 and the right side of the " ' " to only be able to reach 11.

<label for="ft">Feet:</label>
<input type="text" name="ft" id="ft"> 

I am not sure if I would need a RegEx or a mask or what... Any advice would be greatly appreciated!

Maybe RegEx? "[1-2000]'(0[0-9]|1[0-1])""" Or something like that?

  • 2
    Why not use separate ``s? (Or use metric. ) – Biffen Apr 10 '15 at 13:36
  • I wanted to :) that's how I had it set up and of course I was told I must change it to be easier on the user to only fill in one textbox =( –  Apr 10 '15 at 13:39
  • I argued it and said its not as easy as it sounds but was sent away to come up with this solution :/ –  Apr 10 '15 at 13:41
  • Are you going to validate upon form submit, or live? Initial pre-filling can easily be done with ` value="0'00""`, but validation is a different thing. – Wiktor Stribiżew Apr 10 '15 at 13:47
  • I was going to have it live and use the regex for the validation. I cant really use the attribute that way because it is set to a session variable already –  Apr 10 '15 at 13:57
  • well actually id probably have to make it live with the regex also –  Apr 10 '15 at 13:58
  • is it possible to use that regex to set up a mask as well then maybe? –  Apr 10 '15 at 13:59
  • Please check this page: http://stackoverflow.com/questions/17225292/livevalidation-regex-issue. – Wiktor Stribiżew Apr 10 '15 at 14:03
  • right no I get that but what I cant figure out is the first portion of my question prefilling the value If I already have is set up as a session variable `value ="#form.ft#"` –  Apr 10 '15 at 14:09

1 Answers1

1

Something like this should suffice.

^([1-2]?[0-9]{1,3})\'([0-9]|[0-1]{2})\"$

https://regex101.com/r/xD3lC3/3

Regular expression visualization

ʰᵈˑ
  • 11,279
  • 3
  • 26
  • 49
  • Using what technologies? With `html5`, perhaps the pattern attribute? http://html5pattern.com/ – ʰᵈˑ Apr 10 '15 at 15:10
  • I'm unsure what you mean by "Make an input display like that". Perhaps [this](http://stackoverflow.com/questions/29562862/controlling-users-input-for-feet-and-inches/29563135?noredirect=1#comment47275342_29562862) – ʰᵈˑ Apr 10 '15 at 16:09
  • @ZaneZ see: http://digitalbush.com/projects/masked-input-plugin/ - You will need Javascript to do this. Unsure if it can be done with HTML5. – ʰᵈˑ Apr 10 '15 at 16:13
  • I am having a problem still with this reg ex can you help real quick? –  Apr 10 '15 at 19:20
  • for inches it needs to be able do 10 or 11 –  Apr 10 '15 at 19:21
  • but also 01,02,03,04,05,06,07,08,09 –  Apr 10 '15 at 19:21
  • yours is set up to only do singles like 1,2,3,4,5,6,7,8,9, –  Apr 10 '15 at 19:22