$(document).ready(function () {
$.validator.addMethod("pwcheckallowedchars", function (value) {
return /^[a-zA-Z0-9!@#$%^&*()_=\[\]{};':"\\|,.<>\/?+-]+$/.test(value)
}, "The password contains non-admitted characters");
$.validator.addMethod("checkallowedchars", function (value) {
return /^[A-Z]+$/i.test(value);
}, "The field 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))
}, "The password must not contain 3 consecutive identical characters");
$.validator.addMethod("pwchecklowercase", function (value) {
return /[a-z]/.test(value)
}, "The password must contain at least one lowercase letter");
$.validator.addMethod("pwcheckrepeatnum", function (value) {
return /\d{2}/.test(value)
}, "The password must contain at least one lowercase letter");
$.validator.addMethod("pwcheckuppercase", function (value) {
return /[A-Z]/.test(value)
}, "The password must contain at least one uppercase letter");
$.validator.addMethod("pwchecknumber", function (value) {
return /\d/.test(value)
}, "The password must contain at least one number");
$('#myform').validate({
rules: {
"firstname.fieldOne": {
required: true,
checkallowedchars: true,
pwchecklowercase: true,
pwcheckuppercase: true,
pwchecknumber: true,
pwcheckconsecchars: true,
pwcheckspechars: true,
pwcheckallowedchars: true,
minlength: 8,
maxlength: 20
}
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<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>
^[A-Za-z]+$
- rock321987return /^[A-Za-z]+$/.test(value)
- Wiktor Stribiżew