Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3996554
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:17:36+00:00 2026-05-20T07:17:36+00:00

I am assuming I need a regular expression here? I have a zip code

  • 0

I am assuming I need a regular expression here?

I have a zip code field and the zip codes must be in the city limits of Chicago. Luckily all the zip codes begin with 606. So I need to poll the input to make sure that the zip code entered is 5 digits and begin with the numbers 606:

My input is basic enough:

<label for="dzip"><span class="red">&hearts;&nbsp;</span>Zip:</label>
<input name="attributes[address_zip]" id="dzip" type="text" size="30" class="required zip-code" />

And then my script for city was easy enough. I just need to apply it to zip-code as well:

    jQuery.validator.addMethod("Chicago", function(value) {
    return value == "Chicago";
}, '**Recipient must reside in Chicago City Limits**');

May help if I show how the plug-in functions for phone-numbers (US). Basically I need to translate this to zips:

    jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
    phone_number = phone_number.replace(/\s+/g, "");
    return this.optional(element) || phone_number.length > 9 && phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
}, "Please specify a valid phone number");

What does this part do/mean?:

phone_number.replace(/\s+/g, "")

I dropped in the phone part directly from an example on the validate site.

Final answer from all the great (and quick) input here was this:

    jQuery.validator.addMethod("zip-code", function(zip_code, element) {
    zip_code = zip_code.replace(/\s+/g, "");
    return this.optional(element) || zip_code.length == 5 && zip_code.match(^606[0-9]{2}$);
}, "Please specify a City of Chicago Zip Code");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T07:17:37+00:00Added an answer on May 20, 2026 at 7:17 am

    for the length use the .length property

    if($('#dzip').val().length != 5)
      return false;
    

    for the 606 use the substr method

    if($('#dzip').val().substr(0,3) != 606)
      return false;
    

    combined

    $('#dzip').change(function(){
      var val = $(this).val();
      if(val.length != 5 || val.substr(0,3) != 606)
        return false; //not valid
      else
      //do stuff here
    })
    

    Try this:

    jQuery.validator.addMethod("chicago", function(zip, element) {
        zip = zip.replace(/\s+/g, "");
        return this.optional(element) || zip.match("^606[0-9]{2}$");
    }, '**Recipient must reside in Chicago City Limits**');
    

    The above code can be read as

    • Add a method chicago to the validator plugin
    • when the method is called strip all whitespace characters
    • then if the field is not required and it is empty
    • or if it is required and not empty and is 5 digits in length
    • and the first 3 characters are 606
    • return true
    • else return false
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a Perl regular expression to match a string. I'm assuming only double-quoted
I need a regular expression to parse a body of text. Basically assume this
In SQL Server assuming one has columns that need to have the same data
Am I correct in assuming that I always need to explicitly deploy referenced assemblies
Assuming I have only the class name of a generic as a string in
Assuming I have an open source web server or proxy I can enhance, let's
I have a working perl script that grabs the data I need and displays
Is there a single regular expression that can parse a string (in Python and/or
Assuming such a query exists, I would greatly appreciate the help. I'm trying to
Assuming you can't use LINQ for whatever reason, is it a better practice to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.