views:

245

answers:

1

Hi Iam new to j query can any one let me know if there is a way to declare a jQuery.validator.addMethod function and write the java script inside this jquery validator for validating address where it should not take

"PO BOX", "PO BIN", "BIN", "P.O BOX", "P.O BIN", "P.O", "PO"

the above values can be in any case

spaces before, in between and after the above words should also be found and validated. For example: " P O 1234 " should be validated and alert error message.

But "Polo Rd", "Robin Rd", "testbintest" should be accepted as valid addresses

Please help me out with the java script for this thank you

A: 

see link text

(function($){
  $.validAddress = new Array("PO BOX", "PO BIN", "BIN", "P.O BOX", "P.O BIN", "P.O", "PO");
  $.fn.validator.addMethod = function()
  {
     // searched validation in $.validAddress
     ...
     return this;
  }
})(jquery)
andres descalzo
I currently have this in my j query jQuery.validator.addMethod("nopobox", function(value, element) { return this.optional(element) || ! /(P(OST)?\.?\s*O(FF(ICE)?)?\.?\s*(?<!(BOX)|(BIN)))|(^[^0-9]*((P(OST)?\.?\s*O(FF(ICE)?)?\.?)|(?<!(BOX)|(BIN))))/i.test(value);}, "");Please let me know how to use your code with the function name "nopobox"as we are using this function every where in the website where ever we are using the address fields
the above answer is not working in my code any suggestions please I am tring to keep this validation in a free marker tool page with extn .ftl I just replaced the above code with the jQuery.validator.addMethod("nopobox", function(value, element) { return this.optional(element) || ! /(P(OST)?\.?\s*O(FF(ICE)?)?\.?\s*(?<!(BOX)|(BIN)))|(^[^0-9]*((P(OST)?\.?\s*O(FF(ICE)?)?\.?)|(?<!(BOX)|(BIN))))/i.test(value); }, ""); but its not working any suggestions please