.net - jQuery validation plugin -


i using jquery validation plugin validate form on client side. adding new method using addmethod function every html control have regex (custom) attribute. html control like.

<input type="text" id="txtinf" name="txtinf" regex="some regular exp" error="check inf"></input>  $("*[regex]").each(function () {                   var controlid = $(this).attr('name');                       var regex = new regexp((this).attr('regex'));                       var error = $(this).attr('error');                  $.validator.addmethod(controlid, function (value, element) {                  return this.optional(element) || false;              }, error);              $(this).rules("add", { '" + controlid + "': "^[a-za-z'.\s]{1,40}$" });               $(this).validate();         }); 

here giving method name controlid txtinf. in below line, need give txtinf, want use controlid variable instead, want make function generic one. if write controlid directly, searches method same. added method txtinf actually. need way generalise line using controlid variable.

$(this).rules("add", {txtinf: "^[a-za-z'.\s]{1,40}$" });  

the problem can't use variable name referencing in object literal. i've done in past when need manually create json string , pass through parsejson. like:

$(this).rules("add", $.parsejson('{"' + controlid + '":"^[a-za-z\'.\s]{1,40}$" }');  

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 -