Thread: expressions

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    51
    Rep Power
    15
    im newbie as f**k at expressions. Here is one i made to validate a zipcode. Is this like acceptable? or should i make it better?

    $target = $zipcode;

    $pattern = '([0-9]{5})';

    if (!ereg($pattern, $target, $matches)) {
    echo 'Zipcode not acceptable. TIS TIS';
    exit();
    }

    just basically help me out to make this script better... if i can

    cyaz

    sam
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Washington, USA
    Posts
    52
    Rep Power
    15
    Hi Sam,

    Yours is good for 5 digits, here's regexp for 9 digits if you should need

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    $target = $zipcode;
    $pattern = "^([0-9]{5})(-[0-9]{4})?$";
    if(ereg($pattern, $target)) {
    // is valid 9-digit zip code
    } else {
    // is INvalid 9-digit zip code
    }
    [/code]


    ------------------
    <UL TYPE=SQUARE>
    <LI> TD Scripts
    <LI> Script School
    <LI>php-scripts
    </UL>

Similar Threads

  1. regular expressions
    By tdennist in forum C Programming
    Replies: 2
    Last Post: January 18th, 2004, 06:01 AM
  2. regular expressions in Javascript
    By DazAdams in forum JavaScript Development
    Replies: 9
    Last Post: November 24th, 2003, 09:09 AM
  3. xml: How do I divide numbers in XSL expressions?
    By Wildman in forum Beginner Programming
    Replies: 2
    Last Post: June 30th, 2003, 02:28 AM
  4. Multiple IF expressions, one statement
    By basher in forum PHP Development
    Replies: 3
    Last Post: August 3rd, 2002, 01:28 PM
  5. Regular expressions tool
    By Harry in forum PHP Development
    Replies: 6
    Last Post: March 4th, 2002, 04:03 PM

IMN logo majestic logo threadwatch logo seochat tools logo