Input min max not allow special character in react js

334 Views Asked by At

Please point me to sample where i can validate min and max character also none of the special character to be allowed for a input box in react js

1

There are 1 best solutions below

0
Dennis Kats On

Do you mean something like this?

input.oninput = () => console.log(input.checkValidity());
<form>
  <input id="input" type="text" required pattern="[a-zA-Z0-9]+" />
</form>

You can use the pattern attribute to validate that the input only contains characters from particular character sets. The example above only allows 1 or more alphanumeric characters. Pressing "enter" when the input is empty or contains any other character should cause the browser to report a validity error. Moreover, you can use the checkValidity() method to validate the input in JavaScript.