Note: min/max are only valid on type="number"
or type="date"
inputs.
This can be done with pure html. You can set the field to type="number"
and require the min value to be 1000000000
(10 digits) and a max value of 9999999999
(also 10 digits). Then just tack on the required
parameter on the field. The form won't submit unless it validates due to the required
parameter.
<form action="">
<input type="number" min="1000000000" max="9999999999" required>
<input type="submit" value="send">
</form>
Another thing we can do is use a pattern
on a text input
with required
:
<form action="">
<input type="text" pattern="[0-9]{10}" required>
<input type="submit" value="send">
</form>