A jQuery plugin that checks text input against a set of rules you specify and provides feedback in real time.
With the Text Complies plugin, you can specify a set of rules that the input for a specified text field must comply with. As the user types in the field you're checking, the compliance level to the rules is updated, and you can report to the user which rules they're complying with and which rules they're defying.
A typical usage for this plugin is with passwords; you can provide a set of rules (e.g., password must be 8-12 characters, contain one letter and one number, and can't contain spaces), and this plugin list the rules and whether or not the password the user is typing complies with those rules. As the user types the password, this plugin updates the compliance to the rules.
Text Complies allows you to configure several preset rules for compliance checking, each with accompanying text that you can override. Rules you don't configure are not invoked. Your options are:
minLength
: the minimum allowable length of the textminLengthText
: the custom text to use for the minimum length rulemaxLength
: the maximum allowable length of the textmaxLengthText
: the custom text to use for the maximum length ruleminAndMaxLengthText
: the custom text to use when you specify both a minimum length and maximum lengthshowNumbersAsWords
: whether to show numbers less than 10 as wordsnumNumbers
: the minimum number of numbers (digits) the text must containnumNumbersText
: the custom text to use for the number of numbers rulenumUppercaseLetters
: the minimum number of uppercase letters the text must containnumUppercaseLettersText
: the custom text to use for the uppercase rulenumLowercaseLetters
: the minimum number of lowercase letters the text must containnumLowercaseLettersText
: the custom text to use for the lowercase rulenumLetters
: the minimum number of letters the text must containnumLettersText
: the custom text to use for the number of letters ruledisallowed
: an array containing strings that the text can't containdisallowedText
: the custom text to use for the disallowed rulematchField
: the selector of a text field whose value must match the textmatchFieldText
: the custom text to use for the match field rulematchPattern
: the regular expression that the text must matchmatchPatternCaseSensitive
: whether the regular expression is case sensitivematchPatternText
: the custom text to use for the match pattern ruledisallowedPattern
: the regular expression that the text can't matchdisallowedPatternCaseSensitive
: whether the regular expression is case sensitivedisallowedPatternText
: the custom text to use for the disallowed pattern rulevalidateOnStart
: whether to validate the rules on startshowAsFailOnStart
: whether to show all the rules as failing on startoutput
: the selector of an HTML element in which to display the output of the rulesonComplies
: a JavaScript method called if the text complies with all the configured rulesonDefies
: a JavaScript method called if the text doesn't comply with any of the configured rules
<input name="password" type="password" id="password" />
<input name="password_match" type="password" id="password_match" />
<div id="password_compliance">
The compliance goes here
</div>
<input type="button" value="submit" id="myButton" />
<script>
$('#password').textComplies({
output: $('#password_compliance'),
minLength: 3,
maxLength: 12,
disallowed: [ ' ', '$', 'password' ],
matchField: $('#password_match'),
onComplies: passwordComplies,
onDefies: passwordDefies
});
function passwordComplies() {
$('#myButton').removeAttr('disabled');
}
function passwordDefies() {
$('#myButton').attr('disabled', 'disabled');
}
</script>
<style>
.complies {
background-color: green;
}
.defies {
background-color: red;
}
#password_compliance {
border: 1px solid black;
}
</style>
- Author: Rob Warner
- Company: Availity, LLC
- License: MIT