11
I am making a validation form using HTML5 and its own tags to validate the fields. I am using the PATTERN, that limits the character type. But it doesn’t work... Fields are not being locked. "Code", only numbers and "Name", only letters.
Code:
<!DOCTYPE html>
<form>
Codigo: <input type="text" required="required" name="number" pattern="[0-9]"></input>
Nome: <input type="text" required="required" name="text" pattern="[a-z]"></input>
</form>
How to solve this?
I believe it will help you: http://wbruno.com.br/html/validando-formularios-apenas-com-html5/
– Rafael Withoeft
It actually works, the attribute
pattern
does not prevent the user from entering values that are not in the regular expression, but rather avoids these values being sent by the form. Documentation: https://developer.mozilla.org/en/docs/Web/HTML/Element/Input– Eduardo Silva
Additionally, if you want to prevent the user from entering non-accepted values you can do this easily using the plugin
jQuery Mask
(http://igorescobar.github.io/jQuery-Mask-Plugin/).– Eduardo Silva
In fact, as soon as I finished this post I started to realize that... Which are only for regular expressions and there is blocking of the fields, which is what I want. Rodrigo, thanks for the links, will help a lot! Thank you all for confirming what you were thinking.
– GtGtGt