Hi guys. I have been given the task to apply regular expressions on a form validation which I have achieved (using jquery.validate.js). Now, I have to apply a type of regular expressions when the select tag is pointed to US and other type of regular expressions when is pointed to any other country. Any help will be fully appreciated. Thanks in advance.
A:
You could either add logic and call a validation method based on what is selected. Or, you could create a jQuery UI widget factory that tracks which validation is to be used. That may be a little overkill for this though.
Zacho
2010-06-25 14:29:08
+3
A:
If you're using jquery.validate.js when you configure validate and add your rules, try something along the lines of (to add your own rule):
$('#myForm').validate({
rules: {
'myField': {
myRule: function(element) {
var option = element.find('option:selected');
if (option.val() == 'US') {
return // The result of your US only regular expression check
} else {
return // The result of your other regular expression check
}
}
}
}
});
Something like that should get you in the right direction if I understand your question correctly.
roguepixel
2010-06-25 14:38:00
I will start testing this right away.
Ozzy
2010-06-25 14:42:46