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

Imagist
  • 18,086
  • 12
  • 58
  • 77
user151013
  • 31
  • 5
  • This should be a regular expression question. – rahul Aug 05 '09 at 13:09
  • the regular expression has limitations all these can not be obtained in one regex I am currently having a regex which works partially but it will not take robin road the regex i have is /(?:p(?:ost)?\.?\s?[o|0](?:\.|ffice)?)\b|(?:b(?:[o|0]x)|(?:in))\b/i.test(value); – user151013 Aug 05 '09 at 13:17

1 Answers1

0

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
  • 14,887
  • 13
  • 64
  • 115
  • 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 – user151013 Aug 05 '09 at 13:33
  • 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 – user151013 Aug 05 '09 at 14:02