I was not sure if I could ask such a question, but when I saw this one in Meta Stackoverflow, it seems that this question is in order. Well, to my question:
A few months ago, I wrote a validation framework in Javascript. I know that validation frameworks already exist, such as jQuery Validation , but I would like to use a different approach to validation. Modern approaches relate to writing Javascript code to perform validation on form elements. Considering the source code of the form, it is not immediately clear which check is performed for each element. To some extent, this can be fixed using CSS classes that define different types of validation. But I felt that even this was limited, because you cannot easily configure validaton behavior (error messages, etc.). I wanted to do something like annotation-based validation in Java using the JSR-303 Bean Validation or Hibernate Validator .
Since HTML5 allows you to add custom attributes to elements, I decided that I could use this to “annotate” form elements for validation. So, essentially, I came up with this:
<input id = "myInput" name = "myInput" type = "text" class = "regula-validation" data-constraints = '@NotEmpty @IsNumeric @Between(min=1, max=5)' />
Given this basic idea, I created a Javascript framework that:
- Examines the DOM for elements that have constraints defined and binding these constraints to elements
- Allows user restrictions
- Allows software constraint binding
- Checks related restrictions
In addition, the structure has the following functions:
- Verification groups similar to those specified in JSR-303
- Interpolation for error messages
As soon as I created my framework, I tried to get feedback and revise it, but I was not sure where to go to get feedback and a review. I wrote a few blog posts about this and posted it to Digg and Reddit (programming section) without much luck. It seemed to some people that they were interested, but I did not get much more.
Recently, at my workplace, we upgraded an outdated code base (JSP and servlets) and moved it to Spring MVC. When the conversation about verification came up, I broke the scope for my senior architect. I did a little integration and proved the concept, and they seemed interested and gave me the opportunity to add it to the project. So far, I have only had my own humble opinion that this will be a useful way to do validation, so this gave me some confidence that my idea and structure can have some advantages. However, I still needed more involvement and scope. After I realized that Stackoverflow solves such issues, I decided to post it here to get constructive criticism, comments and feedback.
Therefore, without any delay, I would like to introduce Regula . The link I provided refers to the wiki on GitHub, which has all the documentation for the framework. You can download the latest version (v1.1.0) from here .
We are waiting for your comments.
Additional information that is not directly relevant
I played around with the idea of integrating my framework with Spring, i.e. translate beans validation annotations to client-side validation. I recently managed to get this to work, even with validation groups (although there is currently no support for inheritance relationships between client-side groups). Thus, you just have to annotate the properties of the field with validation restrictions, and the client-side validation code is automatically generated. However, I'm new to Spring, so my method is probably not so clean. I would like some feedback on this, so if anyone is interested please let me know. Ideally (and I hope I'm not too pretentious), I would like to contact the Spring people and see if they are interested in this.