validfield.js
What is it?
validfield.js helps you to quickly validate your forms with ease
- No ninja JavaScript skills needed
- It's tiny! Just 4KB!
- Easy to customize
- Allows callback functions
Installation
How to use?
First, include the validfield.js in your HTML document.
Then add the class valid-field to the form you need to validate:
<form action="page.php" name="form" id="form" class="valid-field" data-valid-field-keypress-check="yes">...</form>Additionally, you can add the extra attribute data-valid-field-keypress-check in the form field, to validate the inputs on key press.
Afterwards, just add the attributes to the fields that you want to validate. For example:
<input name="form" type="text" data-valid-field-type="min-length" data-valid-field-minimum-length="5">The attribute data-valid-field-type is the key, used by validfield.js to validate your form fields.
There are many validation types available. Check them out:
min-lengthchecks for a minimum number of charactersmin-equal-lengthchecks for a minimum or exact number of charactersmax-lengthchecks for a maximum number of charactersmax-equal-lengthchecks for a maximum or exact number of charactersemailchecks for a valid emailurlchecks for a valid URLdatechecks for a valid datecustomneeded if you need to create your own validation method
Help?
Check the demo to see with clarity how to use validfield.js.
Tweet me if you have any questions. Bug fixes and pull requests are highly appreciated.
Hope you enjoy :)
License
GNU GPL
Peace!