reg exp help needed

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • racshah
    New Member
    • Apr 2008
    • 6

    #1

    reg exp help needed

    I want to validate the postal codes for 15 different countries. For
    this I have written the perl script shown below. In this script postal
    codes for Netherland, belgium, Italy, Ireland can be validated with
    the use of regular expressions. Still I need to validate countries
    like Greece, Norway, United Kingdom, Sweden, Finland, Schweiz,
    Portugal, Austria, Luxembourg, France, Spain, Deutschland, Denmark. I
    am not getting the regular expressions for these countries.
    Can anyone help me out for these regular expressions??

    Code:
    $country = $ARGV[0];
    $zip = $ARGV[1];
    $countrycode = "";
    $invalid_zip = "";
    
    if($country =~ m/Netherland/)
    {
    	$invalid_zip =1  unless ($zip =~ /[1-9][0-9]00 NL/);
    	print "$country\t$zip\n;"
    }
    elsif($country =~ /Belgium/)
    {
    
    	$invalid_zip =1  unless ($zip =~ /^([1-9]{1}[0-9]{3}$)/i);
    
    	print "$country\t$zip\n;"
    }
    elsif($country =~ /Italy/)
    {
    	$invalid_zip =1  unless ($zip =~ /^[0-9]{5}$/i);
    	print "$country\t$zip\n;"
    }
    elsif($country =~ /Ireland/)
    {
    	$invalid_zip =1  unless ($zip =~ /^\s*$|D\d+w?/i);  ##Ireland does not have postal codes except for Dublin City
    	print "$country\t$zip\n";
    }
    elsif($country =~ /Greece/)
    {
    	$invalid_zip =1  unless ($zip =~ /^[1-8][0-9]{2}$|^[1-8][0-9]{2}[0-9]{2}$/i);
    	print "$country\t$zip\n";
    }
    elsif($country =~ /Norway/)
    {
    	$invalid_zip =1  unless ($zip =~ /^[0-9]{4}$/i);
    	print "$country\t$zip\n";
    }
    
    
    if($invalid_zip)
    {
    
    	print "Invalid Postal Code";
    }
    Last edited by eWish; May 28 '08, 03:10 AM. Reason: Please use code tags
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    What is your question? What the zip code for those nations are? That is up to you to find out, once you know the zip code format you can write a regexp to match it.

    Comment

    Working...