PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Zip Code Form Validation

  1. muhacus
    Member

    I tried to use a form validation hook to validate zip code (5 digit) on my form. But somehow it's not working.

    Here's the code that I enter in my theme functions file.

    http://pastie.org/2005893

    Please advise

    Posted 14 years ago on Wednesday June 1, 2011 | Permalink
  2. Are you using the zip code field that is part of the address field? Or a separate field?

    If you are using a separate field, you might consider using a single line text field and set the character limit to 5: http://grab.by/agfI

    Posted 14 years ago on Wednesday June 1, 2011 | Permalink
  3. muhacus
    Member

    I am using the number field and I need the entry to be numbers and 5 digits in length.

    Actually I tried to used the option where I can specify that the entry must be beween 0 to 99999 but I need it to be 5 digits.

    The code seems to "work" since I get the error message but it gives me that error even when I enter a 5 digit number.

    Posted 14 years ago on Wednesday June 1, 2011 | Permalink
  4. Yep, that worked for me no problem: http://grab.by/aggc

    Ditch the custom code and let me know what error message you are receiving.

    Posted 14 years ago on Wednesday June 1, 2011 | Permalink
  5. muhacus
    Member

    by Using the second method, I don't have an error message. However a zip code must be 5 digits. if someone enter a 3 digit number (ie.. 654 or 8756). the form will be process the wrong info.

    I want to make sure that a 5 digit number is enter (ie 07612).

    Posted 14 years ago on Wednesday June 1, 2011 | Permalink
  6. Are you dealing with any zipcodes that start with zero? If not, try upping the range from 0 - 99999 to 10000 - 99999.

    Posted 14 years ago on Wednesday June 1, 2011 | Permalink
  7. muhacus
    Member

    Yes I do, That's why I was looking at custom validation once I realized that a lot of east coast zipcodes start with 0.

    So I need something that verify that the entry is 5 digits.

    Posted 14 years ago on Thursday June 2, 2011 | Permalink
  8. Hi Muhacus,

    Thanks for bearing with me as we came back to square one. :)

    Try add a "return true" to your validate function like so:

    http://pastie.org/2009604

    Posted 14 years ago on Thursday June 2, 2011 | Permalink
  9. Hi David,

    I'm having the same problem, I'm using the number field with min/max 0-99999 but need to have it accept only 5-digit entries. Where would I add that validate function?

    Posted 14 years ago on Friday June 3, 2011 | Permalink
  10. Hi Redkite,

    Here is the completed functional script: http://pastie.org/2015527

    You would paste this in your theme's functions.php file.

    Posted 14 years ago on Friday June 3, 2011 | Permalink
  11. Is it possible to remove the 'Please enter a value between 00000 and 99999.' text below the zip code number field?

    Posted 14 years ago on Tuesday June 7, 2011 | Permalink
  12. Hi redkite, each field has a custom validation message setting in the GF form admin. You can set that message to whatever you'd like.

    Posted 14 years ago on Tuesday June 7, 2011 | Permalink
  13. Found it, thank you!

    Posted 14 years ago on Wednesday June 8, 2011 | Permalink