- Overview
- Documents
quickValidation.js is a jQuery form validation that makes sense
Source: sandbox.nikorablin.com
quickValidation.js works in a way I think makes sense. Instead of defining rules in the Javascript, I assign them right in the input itself.
Using a data-validate attribute in the input tag, you can string together rules like this required,number,range=0-99, then add the .quickValidate class, add a data-name attribute to name your field for errors, and you're done.
1. INCLUDE JS FILES
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> <script src="js/jquery.quickValidate.js"></script>
2. HTML
<input type="text" name="Name" class="quickValidate" data-validate="required,number,range=0-99" />
3. JAVASCRIPT
$('form').quickValidate();
4. OPTIONS
class | Class of inputs being validated, default: .quickValidate |
notificationClass | Class of notification popup default: .notification |
errorClass | Class of error text in notification default: .error |
5. EXAMPLES
Required Field
<input type="text" name="Name" class="quickValidate" data-validate="required" />
Max Length
<input type="text" name="Name" class="quickValidate" data-validate="maxlength=140" />
Minimum Length
<input type="text" name="Name" class="quickValidate" data-validate="minlength=3" />
Number
<input type="text" name="Name" class="quickValidate" data-validate="number" />
Integer
<input type="text" name="Name" class="quickValidate" data-validate="integer" />
Range
<input type="text" name="Name" class="quickValidate" data-validate="range=1-10" />
<input type="text" name="Name" class="quickValidate" data-validate="email" />
Phone
<input type="text" name="Name" class="quickValidate" data-validate="required" />
Regular Expression Match
<input type="text" name="Name" class="quickValidate" data-validate="expression=/^\d+$/" />
6. CUSTOM ERRORS
You can also have custom error text with this plugin. All you need to do is set the option when calling the quickValidate() function like this:
<script type="text/javascript"> $('form').quickValidate({ 'errorRequired' : '$name is a required field' }); </script>
Use $name to signify when the name of a field is to be used. Use $value when the value of that rule is to be used, and use $min and $max for the minimum and maximum values in ranges.
Here are the errors you can customize:
- errorRequired
- errorMaxlengtn
- errorMinlength
- errorNumber
- errorInteger
- errorRange
- errorEmail
- errorPhone
- errorExpression