Çarşamba, Şubat 23, 2011

Getting along with JQuery,Validation,Masked Input

JQuery is a nice library with whom I havent played till yesterday. Since yesterday I am struggling with this nice library, actually not solely with it but with validation plugin. That plugin is nice too but when it comes to integrating it with another plugin which you guess Masked Input, I was having problems. Because my form is dinamic and I am adding elements whose names are the as previous ones, I have struggled a lot. But at the end I did what I wanted to do. This

jQuery.validator.addMethod("acceptreg", function(value, element, param) {
  return value.match(new RegExp("^" + param + "$"));
});

small code piece helped me a lot when validating text and phone fields and their integration with Masked Input. I know validation plugin normally does validate against phone but my case was different. I declared such a method as described above and used it inside with

tel: {
required: true, minlength:11, maxlength:11,acceptreg: "[0-9]{3}-[0-9]{7}"
},

I did some dom manipulation with dom adding and removing dom elements too.I struggled a lot but after I am pleased to work deeper with javascript and JQuery.

 

Hiç yorum yok: