jQuery Validation Library for Twitter's Bootstrap v2.0
Spitshine requires the use of Bootstrap 2.0's new control-group structure and syntax for form elements, styles are applied to parent().parent() of the element in question.
$(document).ready(function() {
$('#form').spitshine();
// Custom method, useful for AJAX and other more comples validators, or just inserting your function.
$('#form').spitshine('method','required', function(selector) { if ($(selector).val() == '') { return false; }});
// Don't use Bootstrap? Override the internal class functions to use with your own DOM structures.
$('#form').spitshine('method','field_error', function (selector) {
$(selector).parent().parent().addClass('error');
$(selector).parent().parent().removeClass('success');
});
//Optional
$('#submit').bind('click', function() { return $('#form').spitshine('valid'); });
});
<form id="form">
<div class="control-group">
<div class="input">
<input class="valid-required valid-email valid-custom-required" id="email" name="email" type="text" />
<span class="help-inline"></span>
</div>
</div>
<!-- Optional -->
<input type="submit" name="submit" id="submit" value="submit" onclick="return $('#form').spitshine('valid');" />
</form>
-
spitshine (interface/driver method)
-
() - (Initialization/Constructor)
-
('valid') - (returns true/false depending on entire form validation)
-
('method', (method name), (function)) - Add a custom method to the mix, or use to override the selector/class functions
-
-
valid-required
-
Checks input type=text for val() === ''
-
Checks input type=checkbox for val() === ''
-
Checks input type=select for attr('checked')
-
-
valid-email
- Simplified email regex (/\S+@\S+.\S+/) please confirm email, do not rely on validation.
-
valid-numeric
- Checks for a numeric only string
-
valid-alpha
- Checks for alphabetic only entry
-
valid-phone
-
Checks common digit structure and formatting
-
Also checks for exclusion list of prefixes and exchanges
-
-
valid-length-(n)
- Validates exact length (valid-length-5 for zipcodes)
-
valid-max-length-(n)
- Validates a max length
-
valid-custom-(function)
- Calls custom (function) that was added, is passed the current selector