How to match a value to a string within "rules" using jquery validate.js (bassistance.de)
I want to check if a form radio input value matches a string exactly, something like "equalTo" but just to match a string and not anoth开发者_运维技巧er field input but can't find if there is a simple way to do this similar to using "equalTo".
As below I want the form field "foo" value to match "bar" exactly and was hoping to replace the ????????s with a simple command if this is possible?
If not I would really appreciate some help showing how I can implement a string match within the "rules" method.
$("#this_form").validate({
rules:{
            name:{
                 required:true
                 },
             foo:{
                 ????????: "bar",
                 required:true
                 }
        }
});
So here I want the form to only validate if the value of foo is "bar" and not if the value is "manchu".
< input type="radio" name="foo" value="bar" />
< input type="radio" name="foo" value="manchu" />
(I think the reason is pretty obvious, the answer to foo needs to be bar otherwise I do not want the form to submit.)
You can do something like this:
  jQuery.validator.addMethod("myFunc", function(val) {
    if(val=='myString'){
      return true;
    }
    return false;
  }, "Values do not match.");
You can then use this method 'myFunc' like you would use the built in email function.
...
foo:{
     myFunc:true
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论