ASKER
ASKER
jQuery.validator.addMethod("filename", function(value, element) {
return this.optional(element) || /^(?!^(PRN|AUX|CLOCK\$|NUL|CON|COM\d|LPT\d|\..*)(\..+)?$)[^\x00-\x1f\\?*:\";|/]+$/g.test(value);
}, "Please specify a valid file name");
$("#myform").validate({
rules: {
fileName: "filename"
}
});
Have a look at the documententation, this will show you how to set-up custom validator methods and look at the built in methods for how to use them.
ASKER
rules: {
fileName: "filename"
}
Where filename (all lowercase) is the name of the method you have added, and fileName (java case) is the name of your field.
ASKER
jQuery.validator.addMethod("filenameOrxEquals1", function(value, element) {
return this.optional(element) || x==1 || /^(?!^(PRN|AUX|CLOCK\$|NUL|CON|COM\d|LPT\d|\..*)(\..+)?$)[^\x00-\x1f\\?*:\";|/]+$/g.test(value);
}, "Please specify a valid file name");
$("#myform").validate({
rules: {
fileName: "filename"
}
});
...
rules: {
fileName: "filenameOrxEquals1"
}
this sets up the method called filenameOrxEquals1 and then uses it in the rules for the fileName field.
JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.
TRUSTED BY