Skip to content

24 ways to impress your friends

Vote down?

Adam Silver

Ok, to answer my own fears somewhat I have been reading

http://dev.w3.org/html5/spec/Overview.html#the-constraint-validation-api

There are a bunch of methods and properties that can be checked against a field in JavaScript to test whether something is valid or not etc.

However this level of basic input validation doesn’t really cater for a lot of the needs of a website with something more than a tiny contact form or a comments form such as the one I am writing in for this.

There are further levels than just required/min-length/max-length/regex.

Sometimes you may want to do cross field validation i.e. “when a particular field is checked then another field should be mandatory”.

In short, I think a lot of the improvements being made to form fields might end up not being as useful as some may think.

What really works in the HTML4 input spec/behaviour is that only the maxlength is provided as an attribute and that works because the user is forced not to type something bad – it is impossible, therefore an error can never occur with regards to that validation rule. The really bespoke stuff can be written by the developer.

I am not sure what the best way forward is but I have developed the JS form validation frameworks for many different clients and taken advice on certain aspects by the RNIB. Whilst being able to apply powerful client-side validation is always the same, the visual output can be very different.

These extra properties and methods only cater for some very basic validation rules. I would have to integrate a branch of validation for the native api and a branch for the custom api (which I create in my js validation framework)