Awkward Check - A jQuery Plugin
This article was last updated on Dec 08, 2011Awkward Check is an easy to implement jQuery plugin that makes it super easy to implement validation of HTML-forms. It has many useful features. One is real-time validation, which means that a field is validated as soon as it’s loses focus. Another one is custom validation rules which opens up for ajax based validations.
The look of the validation is 100% customizable via HTML and CSS.
Implementation Example
<!DOCTYPE html>
<html>
<head>
<title>Awkward Check - Demo #1</title>
<link rel="stylesheet" href="css/style.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript" src="jquery.aw-check.js"></script>
<script type="text/javascript">jQuery( document ).ready(function() { aw_check_init('#form'); });</script>
</head>
<body>
<form id="form" method="post">
<div class="input-box" checkfield="#input-name" checkrule="text">
<label>Name</label>
<input type="text" id="input-name" name="input-name" />
<span class="check"></span>
<span class="error"></span>
</div>
<div class="input-box" checkfield="#input-email" checkrule="email" checkerror="Please enter a valid e-mail address">
<label>E-mail</label>
<input type="text" id="input-email" name="input-email" />
<span class="check"></span>
<span class="error"></span>
</div>
<div class="input-box" checkfield="#input-phone" checkrule="phone:empty" checkerror="Please enter a valid phone number">
<label>Phone</label>
<input type="text" id="input-phone" name="input-phone" />
<span class="check"></span>
<span class="error"></span>
</div>
<div class="input-box">
<input type="submit" name="submit" value="Submit form" onclick="javascript: return aw_check('#form');" />
</div>
</form>
</body>
</html>
Configuration Options
Functions
aw_check_init( identifier, auto )
Run this, in the jQuery-document-ready-function, to initialize the form validation. The function takes two parameters:
identifier (string) Identifier of the form to validate.
auto (bool) Activate real-time validation.
aw_check(‘#id-of-the-form-to-validate’)
Run this when clicking the submit button. If the form do not validate the function returns the value false.
Element Attributes
class
The class ”input-box” MUST be included.
checkfield
The identifier of the field to validate.
checkerror (optional)
The error message to show.
checkrule
The validation rule for the field.
text, email, check, phone, number and custom rules
Add :empty if it’s an optional field that you want validated.
checklabel
The value for the overlay label.
Custom Validation Rules
Add custom validation rules (checkrule) by adding regular expressions or functions to the array named aw_check_custom_validation.
aw_check_custom_validation['time'] = /^([0-1][0-9]|[2][0-3]):([0-5][0-9])$/;
Known Bugs in v.1.3.1
No known bugs yet =)
If you find any bugs, or solutions on how to solve them, keep us updated. Thanks!
Changelog v.1.3.1
- A small bug fix for custom validation functions.
Upcoming Features
If you have any features you want in upcoming versions, let us know.
-
Anonym
-
Jennifer085
-
http://www.awkward.se Joakim Strandell
-
Michael
-
http://www.awkward.se Joakim Strandell
-
Michael
-
Michael
-
Pasha
-
http://www.awkward.se Joakim Strandell
-
http://www.awkward.se Joakim Strandell
-
Pasha
-
Dallas
-
http://www.awkward.se Joakim Strandell
-
Pasha
-
http://www.awkward.se Joakim Strandell
-
Noreply at Google
-
http://twitter.com/gethmyster Lee Gething
-
http://twitter.com/gethmyster Lee Gething
-
Ikenna Ugwuh
-
Nathan-nz
-
http://www.awkward.se Joakim Strandell
-
Serghey Sancheev
-
Markus
-
Markus
-
http://www.awkward.se Joakim Strandell
-
Scolas
-
http://twitter.com/gethmyster Lee Gething
-
insomniac