Home > database >  How can I make my form only except values that the user entered that are between 1 - 100 (e.g like f
How can I make my form only except values that the user entered that are between 1 - 100 (e.g like f

Time:08-15

I want this to apply to the age input box and to only except the values that are between 1 - 100,in 'javascript'.

 <h1>Form</h1>

<form name="form"  onsubmit="myFunction()" method="post" action="">

<div>
    <input type="text" required minlength="3" maxlength="20" placeholder="Enter your first name">
</div>

<div>

    <input type="text" minlength="3" maxlength="20" required placeholder="Enter your last name">
</div>

<div>
    <input id="age" required name="number" type="number" placeholder="Enter your age">
</div>

<div>
    <input type="text" required placeholder="Enter your email">
</div>

<div>   
    <input type="submit" required value="Submit">
</div>

</form>

CodePudding user response:

The attributes min and max is probably what you're looking for.

<input id="age" required name="number" type="number" placeholder="Enter your age" min="1" max="100">

You may need to clarify what you mean by "only except the values that are between 1 - 100,in 'javascript'." if not.

  • Related