I am creating a form that will allow a user to enter a birthday with month, day and year. For year, I am trying to write the html code such that it will only allow positive number and also limit it to 4 digits. Here is the code in question:
<input type="number" name="year" maxlength="4" max="9999" min="0" step="1" placeholder="YYYY" p="[0-9]{4}" style="color:#888;" required/>
I've scoured the web for a solution to what I am trying to do but every time I try it, it will allow me to enter a number that is greater than 4 digits... basically I am trying to limit the user to enter a valid birth year:
Any advice?? thanks in advance!!
Birth year greater than 4 digits input
thank you kennytm, your link has answered by question. I just needed to add this
onKeyPress="if(this.value.length==10) return false;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With