I want a text field where users can write only 1, X or 2 (like a bet). Only one of them, so limited to one character and only these three options. Also the X should be capitalized and not a small x.
Thanks in advance
Do not know what to try :/
I want a text field where users can write only 1, X or 2 (like a bet). Only one of them, so limited to one character and only these three options. Also the X should be capitalized and not a small x.
Thanks in advance
Do not know what to try :/
3
Answers
<input type="text" pattern="^(1|X|2)$" />
That sounds like a job for radio/button/dropdown, but if you insist using an
input
, here’s a solutionAs a bonus, here’s a more "user friendly" approach that automatically convers small
x
intoX
and replace the user input right away without requiring user to delete the previous one first.About the Problem
So you want text field with max-length of 1 and user can only input either 1 , X ,2.
Approach
first create a input field and with attribute maxlength="1" will limit its length.
Now we have to validate the input it must be from required values i.e either 1,X,or 2 so that thing will be handled by validate function.