javascript - Custom form validation using jquery plugin, based on attributes -


i using jquery valdiation plugin validating form @ client side. want validation like.

<input type="text" id="txtinf" regex="/some regular expression/" error="inf mandatory"></inf> 

here regex , error custom attributes. field validated against given regular expression in regex , if regular expression text fails error meessage should shown.

i tried add method validator this.

 $("*[regex]").each(function () {              $.validator.addmethod($(this).attr('id'), function () {                 return this.optional($(this)) || $(this).attr('regex').test($(this).text());             }, $(this).attr('error'));  }); 

but there issue, approach. please let me know, if thinking right. if there other approach in mind, please let me know. thought process welcomed.

i haven't used plugin, looks you'll error use of test().

$(this).attr('regex').test($(this).text()); 

should

var regex = new regexp($(this).attr('regex')); regex.test($(this).text()); 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -