Home:ALL Converter>What JavaScript library to use for client-side form checking?

What JavaScript library to use for client-side form checking?

Ask Time:2009-02-23T13:52:55         Author:PTBNL

Json Formatter

Over the years, I've dabbled in plain JavaScript a little, but have not yet used any JavaScript/AJAX libraries. For some new stuff I'm working on, I would like to use a js library to do client-side form validation, and want to know which would be best for that. By best, my criteria would be: quick and easy to learn, small footprint, compatible with all popular browsers.

Edit: Thanks for the ASP suggestions, but they're not relevant to me. Sorry I didn't originally mention it, but the server is a Linux box running Apache and PHP. As I know I should, I plan to do server side validation of the input, but want the client side validation to improve the users' experience and to avoid as much as possible having the server reject invalid inputs.

Edit 2: Sorry I didn't reply for months! Other priorities came up and diverted me from this. I ended up doing my own validation routines - in addition to the good points made in some of the answers, some of the items I'm validating are rarely used in other applications and I couldn't find a library with that sort of validation included.

Author:PTBNL,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/576631/what-javascript-library-to-use-for-client-side-form-checking
KooiInc :

I don't use libraries myself, but dived into some (like prototype, (yui-)ext, the seemingly omnipresent jquery, mootools) to learn from them and extract some of the functions or patterns they offer. The libraries (aka 'frameworks') contain a lot of functionallity I never need, so I wrote my own subset of functions. Form checking is pretty difficult to standardize (except perhaps for things like phone numbers or e-mail address fields), so I don't think a framework would help there either. My advice would be to check if one of the libraries offer the functionallity you look for, and/or use/rewrite/copy the functions you can use from them. For most open source libraries it is possible to download the uncompressed source.\n\nIt needs to be said (by the way and perhaps well known allready) that client side form checking is regarded insufficient. You'll have to check the input server side too.",
2009-02-23T12:15:31
Kristen :

Before AJAX Libraries I used Validation.JS by Matthew \"Matt\" Frank.\n\nThe basic idea is that you include a JS file and then add attributes to your INPUT statement.\n\nExample:\n\n<input name=\"start-date\" type=\"text\" \n display-name=\"Start Date\" date=\"MM/YYYY\" required=\"@getRequired()\" />\n\n\nField will be validated as a date in MM/YYYY style. Any error message displayed will refer to the field as \"Start Date\". The \"@\" prefix will cause the getRequired() function to be evaluated at run-time.\n\nA variety of things are provided as standard (Currency, Date, Phone, ZIP, Min/Max value, Max length, etc), and there is a keystroke filter; alternatively you can roll your own - most easily by just defining a Regular Expression for the field, but you can add Javascript Functions to be called to make the validation.\n\nThere are pseudo events for handlers to catch before/after field and form.\n\nIn additional to Attributes in the INPUT statement, validation actions can be applied to the field by JS:\n\n// Set field background when in error state\ndocument.MyForm[\"INVALID-COLOR\"]=\"yellow\";\n\n// Show error messages on field blur\ndocument.MyForm[\"SUPPRESS-ONCHANGE-MESSAGE\"]=true;\n\ndocument.MyForm.MyField.REQUIRED = true;\ndocument.MyForm.MyField.DisplayName=\"Password\";\n\n\nValidation.JS is 28K (uncompressed)\n\nI've had a bit of a trawl around to try to find an HTML file you can easily get to with details, but I can't fine one standalone that I can link to.\n\nThe source code is here:\n\nhttp://code.google.com/p/javascript-form-validation/source/browse/#svn/trunk\n\nand the DOCs are in the HTML files - but you can't view those as HTML, you have to download them and then view them, as far as I can make out",
2009-02-23T13:32:35
Julien Roncaglia :

You could use jQuery and it's Validation plugin.",
2009-02-23T05:55:52
yy