I have a form and I need this field
%pre%
In case it is the phone, it will display the following error messages:
If the user types less than 8 digits, an error message appears, a %code% .
If the user types "-" which is an invalid character, an alert with = %code%
And if the number is valid (8 digits) nothing appears.
My code:
%pre%
It's not working.
The reference in the HTML to the javascript has to be by onKeyup if possible, as the javascript has to check after the user types.
Sincerely,
Gabriel
______ azszpr127718 ___
I suggest using the validation supported by the browser itself. This only works if the browser supports HTML5
To use something more complete or different you can continue to use the onchange event with this automatic validation:
______ azszpr127721 ___
You can do this:
Remembering that it is more practical to limit size by html using maxLength, and using onblur prevents it from showing the message at all times when typing.
______ azszpr127729 ___
To complement, I'll leave a more complete version of @GabrielRodrigues' answer.
I made using the jQuery Mask Plugin , I believe it increases the usability of the field since it already comes formatted, in addition it it also "prohibits" any letters or any non-digit characters from being typed.
______ azszpr127738 ___
I got it!
I used the answer from @Bruno Costa and Js from @Gabriel Rodrigues.
It just looks like this:
%pre%
___