At work we have a web application that is pretty old. So we have a hodge-podge of form-validation solutions. There is a lot of duplicated validation logic, a lot of custom validation logic, some stuff that has been implemented with jQuery validation, some stuff from the bassistance.de validator, and some of the new code even has HTML validation, etc. You get the picture.
We're doing a huge cleanup and refactor on the client side and my task is to figure out ONE WAY to do all the validation. Initially I was going to go with one of the solutions we are already using like jQuery validation, or the bassistance validation plugin. But then I was looking at HTML5 validation and I really like how you can tell from looking at the element what validation rules apply to it. So I decided to go this route. But then I realized that for custom validation, I kind of still have to write them out in Javascript and then there is no easy way to tell if that custom validation rule applies to the element. Basically, I want to do something like this:
<input type="text" required="true" customValidationRule="true" />
Or something like that. But it gets more complicated than that. Some of our custom validation rules require certain parameters and it would be awesome if I could do something like this:
<input type="text" required="true" customValidationRule="true" customValidationRuleParamOne="5" customValidationRuleParamTwo="6" />
I also want to validate certain things as groups, like a person's address details, or credit card details, or things like that. For example, it would be useful to do something like this:
<input type="text" name="street" required="true" group="addressGroup" />
<input type="text" name="city" required="true" group="addressGroup" />
<input type="text" name="state" required="true" group="addressGroup" />
<input type="text" name="zip" required="true" group="addressGroup" />
Then I can just validate everything in "addressGroup" and it would automatically validate all those elements.
To make things more complicated, we also have server-side validation that we do using JSR-303. We currently make AJAX calls for this but I would like to somehow attach that to the element as well using an attribute like asyncValidationRule="true" or something. Can you do something like that in HTML5?
I understand if I am asking for too much. But is there a validation library that has at least some of these features? What I am going for most is the ability to specify validation rules on the element itself. It is ok if it doesn't have any of the other requirements. I can work around that somehow.