Monday, January 10, 2011

How to check if script tags are entered in a field


jQuery.validator.addMethod("disableScript", function(text, element) {
return (text.match(/\<\bscript\b/i) || text.match(/\<\/\bscript\b/i))?false:true;
}, "Script tags are not allowed");


And how to use it?? It's very simple.

Just add this method to the list of rules to validate the particular input field.

Example:-

rules: {
first_name: {required: true, disableScript: true},
comment: {disableScript: true}
}

Note:
The JQuery validator plugin js file should be included in the page for this to work.