Tuesday, October 3, 2023
 Popular · Latest · Hot · Upcoming
114
rated 0 times [  119] [ 5]  / answers: 1 / hits: 27510  / 15 Years ago, sat, june 27, 2009, 12:00:00

I am using the jquery validation plugin from: http://bassistance.de/jquery-plugins/jquery-plugin-validation/



How can I add a regex check on a particular textbox?



I want to check to make sure the input is alphanumeric.


More From » jquery

 Answers
5

Define a new validation function, and use it in the rules for the field you want to validate:



$(function ()
{
$.validator.addMethod(loginRegex, function(value, element) {
return this.optional(element) || /^[a-z0-9-]+$/i.test(value);
}, Username must contain only letters, numbers, or dashes.);

$(#signupForm).validate({
rules: {
login: {
required: true,
loginRegex: true,
}
},
messages: {
login: {
required: You must enter a login name,
loginRegex: Login format not valid
}
}
});
});

[#99228] Tuesday, June 23, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
monicag

Total Points: 651
Total Questions: 106
Total Answers: 104

Location: Grenada
Member since Sun, Dec 20, 2020
3 Years ago
monicag questions
;