0

I have a user input and I only want them to be able to enter a number between 0-3. currently I have it restricted to only numbers and a maxlength of 1 but how can I tweak this to only allow 0-3 to be entered in the input? I understand I can change the type to number, set a min and a max but I have javascript that prevents this form from submitting so I don't think that will work in my situation.

Jquery

$(document).on("keypress", ".form-control", function(evt) {
evt = (evt) ? evt : window.event;
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
    return false;
}
    return true;
});

input

<input data-src='ROOF_ASSEMBLY' class="form-control" type="text" maxlength="1">
  • 1
    Why not use a dropdown since it's only 4 options? – adiga Nov 03 '22 at 14:39
  • I never thought to use a select. I'm using data-src attributes and I didn't think that would work with select elements but I tested it out and this will be easier for my project. Thank you @adiga – ProfoundHypnotic Nov 03 '22 at 15:59

0 Answers0