views:

47

answers:

2

I want to write a plugin to validate forms. I have made detailed research about that but I want to write it with my own way. I dont want to write so many lines of code when using the library. It should be easy to use.

I found a jQuery library for validation. It uses HTML classes. For example if you want to a field with presence validation you just add the field required class done but I am not sure this is this is clear way. So I am confused with this, so anyone can tell me which is the best way to write a form validation library?

A: 

Actually the I found the jQuery validation plugin way is a very nice of dealing with validation logic. Here are some my reasons for it..

  • Its un-intrusive. You need no extra markup on your form elements.
  • Used by many other plugins so replacing one with a better one should be relatively simple
  • Elements having same class will get same validation logic and chance of missing is rare (all date elements will get same date logic, although you can easily override)
  • You can use the same class to add extra logic and same UI look and feel (obvious) too and you are sure that they all behave the same. (I add a jquery rule to make all date elements has a date picker too)
  • Adding and removing rules can be done relatively easy with out change to your markup.
Teja Kantamneni
adding class name and use it for validation is a good way what you think about that? I am not sure
Lorenzo
@Lorenzo I think it is a great idea and my points are to support it
Teja Kantamneni
Allright I will work on it. It will use class names and custom attributes such as maxlength and it will be a plugin so you can say $(form).validate(). It will return true or false. If return false it will return also validation errors. Also I am from Turkey so the library should be multi language support. You shold not always write a form for example you may want to validate an input in a div but there is no form, it will validate it and return result.
Lorenzo
@Lorenzo Check the framework at http://bassistance.de/jquery-plugins/jquery-plugin-validation/ . I am not sure about multi language support. But there are other features which you need to look at.
Teja Kantamneni
I have looked at days ago, -I am not sure- but I guess the plugin is always requires a form so you can not validate an input in a div without a form also I find its documentation is confusing. I will check it out again and extend it with in my minds :-)
Lorenzo
A: 

I the method you describe is a good one. You can easily query anything with a class of "required", determine its type and check for a selected value. You can do this for all input types.

Diodeus