JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/additional-methods.js"></script>
<form id="myform">
<input type="text" name="firstname.fieldOne" /><br/>
<br/>
<input type="submit" />
</form>
JavaScript
$(document).ready(function () {
$.validator.addMethod("pwcheckallowedchars", function (value) {
return /^[a-zA-Z0-9!@#$%^&*()_=\[\]{};':"\\|,.<>\/?+-]+$/.test(value) // has only allowed chars letter
}, "The password contains non-admitted characters");
$.validator.addMethod("pwcheckspechars", function (value) {
return /[!@#$%^&*()_=\[\]{};':"\\|,.<>\/?+-]/.test(value)
}, "The password must contain at least one special character");
$.validator.addMethod("pwcheckconsecchars", function (value) {
return ! (/(.)\1\1/.test(value)) // does not contain 3 consecutive identical chars
}, "The password must not contain 3 consecutive identical characters");
$.validator.addMethod("pwchecklowercase", function (value) {
return /[a-z]/.test(value) // has a lowercase letter
}, "The password must contain at least one lowercase letter");
$.validator.addMethod("pwcheckrepeatnum", function (value) {
return /\d{2}/.test(value) // has a lowercase letter
}, "The password must contain at least one lowercase letter");
$.validator.addMethod("pwcheckuppercase", function (value) {
return /[A-Z]/.test(value) // has an uppercase letter
}, "The password must contain at least one uppercase letter");
$.validator.addMethod("pwchecknumber", function (value) {
return /\d/.test(value) // has a digit
}, "The password must contain at least one number");
$('#myform').validate({
// other options,
rules: {
"firstname.fieldOne": {
required: true,
pwchecklowercase: true,
pwcheckuppercase: true,
pwchecknumber: true,
pwcheckconsecchars: true,
pwcheckspechars: true,
pwcheckallowedchars: true,
minlength: 8,
maxlength: 20
}
}
});
});