validator-demo icon indicating copy to clipboard operation
validator-demo copied to clipboard

HTML5 constraint validation

Open kevinmickey opened this issue 8 years ago • 1 comments

It might make sense to use HTML5 constraint validation, in particular setCustomValidity().

See https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation#Constraint_API's_element.setCustomValidity()

kevinmickey avatar Jun 19 '16 05:06 kevinmickey

There are only currently two client side validations done in the script: https://github.com/mailgun/validator-demo/blob/master/mailgun_validator.js#L77-L80 Both of which are very fast because they only use string functions.

We actually don't want to completely validation the domain name on the client side to take advantage of mailgun's "Did you mean?" feature to help the user correct their input, otherwise the built in browser email validation in the HTML5 Validation API would be a nice optimization to the script.

Safari currently doesn't actually display the validation message to the user when it blocks the form submission: http://caniuse.com/#feat=form-validation Until that is resolved it is probably best to not use setCustomValidity() to avoid displaying two error messages to the user.

msigley avatar Sep 19 '16 17:09 msigley