Simple idea to use jquery custom URL validation INSTEAD OF URL validator

by barkkathulla 2013-03-01 16:16:53

Simple idea to check custom validate in URL validator



This idea is most useful to avoid spam contents and unwanted posts in oursite.


Part 1:


Example validate field inside of form element


in the above sample textbox should contain rel="owner url"(E.g)fancygreetings.com

Part 2:


Example of Custom URL validation in jquery


jQuery.validator.addMethod ("domainChk", function (value, element, params) {

if (this.optional (element) )
return true;
//--- Get the target domain, this will be in the rel attribute.
var requireddomain = $(element).attr ("rel");
var regExp = new RegExp ("^http?://(www.)?" + requireddomain + "/", "i");
var regExp = new RegExp (targDomain);

return regExp.test (value);
},
function errmess (params, element) {
return "This must be a valid URL for " + $(element).attr ("rel");
}
);

jQuery.validator.addClassRules ( { domainChk: {domainChk: true} } );


Part 3:


Usage
*To avoid spam
*To get proper unique input what we want
*Easy way to review for admin
1075
like
0
dislike
0
mail
flag

You must LOGIN to add comments