Posted By

StevenW721 on 07/11/12


Tagged

javascript jquery validate not equal not-equal


Versions (?)

jQuery Validate Not Equal


 / Published in: PHP
 

URL: http://stackoverflow.com/questions/3571347/how-to-add-a-not-equal-to-rule-in-jquery-validation

Adds a method to the jQuery Validation plugin (http://bassistance.de/jquery-plugins/jquery-plugin-validation/) to return false if the field equals a specified string

  1. // Add method
  2. jQuery.validator.addMethod("notEqual", function(value, element, param) {
  3. return this.optional(element) || value != param;
  4. }, "Please specify a different (non-default) value");
  5.  
  6. // Use example
  7. $("#form").validate({
  8. rules: {
  9. nameField: { notEqual: "Your Name" }
  10. }
  11. });

Report this snippet  

You need to login to post a comment.