jquery validation, how to check a select box is not the default value

1. You can write your own rule!
 // add the rule here
 $.validator.addMethod("valueNotEquals", function(value, element, arg){
  return arg != value;
 }, "Value must not equal arg.");

 // configure your validation
 $("form").validate({
  rules: {
   SelectName: { valueNotEquals: "default" }
  },
  messages: {
   SelectName: { valueNotEquals: "Please select an item!" }
  }  
 });

2. An easier solution has been outlined here: [jQuery] Validate select box
Make the value be empty and add the required attribute

评论

热门博文