1

I'm working on a html form, and I like to know if there is a tool or way to restrict the user to some rules in inputs, i.e.: -Don't allow the user to put more than 2 digits after the dot -Don't allow the user to put more than 1 dot

I was thinking on regular expressions but how to apply that live.

Thank you.

Logic
  • 25
  • 6
  • 3
    Possible duplicate of [Allow 2 decimal places in ](https://stackoverflow.com/questions/34057595/allow-2-decimal-places-in-input-type-number) – emtei Jun 12 '18 at 21:00
  • Possible duplicate of [Restrict characters in input field](https://stackoverflow.com/questions/22708434/restrict-characters-in-input-field) –  Jun 12 '18 at 21:01

1 Answers1

0

You can run a form validation process with JavaScript. Use HTML DOM to get all the input fields, then use string manipulation to search it's "value" attribute for characters.

document.getElementById() and similar methods can retrieve different elements on the page. After the getElement method you used to find the input field, type ".value" and then it should return whatever is in that field. Then run that through something like data.includes() or similar to check for certain characters.

commandertuna
  • 104
  • 1
  • 13