I need some RegEx for my special jQuery validator validation methods. The first one, which I thought would be easy, is simply limiting the username to US letters, numbers, and special characters. I came up with ^[a-zA-Z0-9]+$, but it does not work. Perhaps this is due to how it appears in the function:
$.validator.addMethod(
"legalName",
function(value, element) {
return (element.value != "^[a-zA-Z0-9]+$");
},
"Use a valid username."
);
The second is password verification, which is essentially the same restriction with the addition of the required number of certain characters, such as uppercase, numeric, etc. I understand, as soon as I get the RegEx username by password, it will not be too hard, just a question about installing in {1}, etc. In expression.
The last part of my question is how to add a second method ("legalPassword") to the original one .addMethodor do I need to create a whole different one $.validator.addMethod?
$(document).ready(function() {
$("#form1").validate({
rules: {
username: {
legalName: true,
required: true,
maxlength: 35
}
},
});
});
and table code:
<form id="form1" method="post" action="">
<div class="form-row"><span class="label">Username *</span><input type="text" name="username" /></div>
<div class="form-row"><input class="submit" type="submit" value="Submit"></div>
</form>
New code (still not working):
$.validator.addMethod(
"legalName",
function(value, element) {
/^[a-zA-Z0-9]+$/.test( value );
},
"Use a valid username."
);