[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

validation - usa and canada zipcode

Posted on 2005-04-11
9
Medium Priority
?
1,400 Views
Last Modified: 2012-06-21
hi,

i able to validate how to check the zip code for usa

but how should i check for canada?

if the user clicks on the usa then should validate the zip code whether there is only 5 digits number

and if the user select as Canada as a country then it should validate the postal code for ane example: V5L3T2.

appreciate your help

thanks
0
Comment
Question by:service2001
  • 4
  • 3
  • 2
9 Comments
 
LVL 4

Expert Comment

by:vladimir_kalashnikov
ID: 13757917
just check to see if:

1) is 6 characters long
2) if the 1,3,5 characters are letters and if the 2,4,6 characters are numbers

you can check to see if a character is a letter by:

string postalCode = "V5L3T2";

if(postalCode[0] >= "a" && postalCode[0] <= "z")

you can do that for every character.  Note that for numbers if would be >= "0" and <= "9"
0
 

Author Comment

by:service2001
ID: 13757946
i guess there is validation control in asp.net called regular expression can't i use that?
0
 
LVL 4

Expert Comment

by:vladimir_kalashnikov
ID: 13757955
yeah, you can use that.  It just requires you to say what the expression format should be.  That would be a good idea to use if this is for form validation.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 4

Expert Comment

by:vladimir_kalashnikov
ID: 13757990
here is a link if you want to use a regular expression and don't know how:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconCOMRegularExpressions.asp
0
 

Author Comment

by:service2001
ID: 13758385
does not help the link
0
 

Author Comment

by:service2001
ID: 13758419
i try giving this on page_load


        If Me.ddlCountry.SelectedItem.Text = "USA" Then
            Me.regexpValidator_PostalCode.ValidationExpression = "\d{5}(-\d{4})?"
        ElseIf Me.ddlCountry.SelectedItem.Text = "Canada" Then
            Me.regexpValidator_PostalCode.ValidationExpression = "[A-Z]\d[A-Z]\s\d[A-Z]\d"
        End If

but it does not work

how should i use, based on the user selection usa or canada the validaitonexpression should be assign and only check the validation of which country the user selected.
0
 
LVL 7

Accepted Solution

by:
nisarkhan earned 200 total points
ID: 13759526
try this:

Expression:  ^((\d{5}-\d{4})|(\d{5})|([A-Z]\d[A-Z]\s\d[A-Z]\d))$
 
Sample Matches:  
44240|||44240-5555|||T2P 3C7
Sample Non-Matches:  
44240ddd|||t44240-55|||t2p3c7
Description:  This expression matches three different formats of postal codes: 5 digit US ZIP code, 5 digit US ZIP code + 4, and 6 digit alphanumeric Canadian Postal Code. The first one must be 5 numeric digits. The ZIP+4 must be 5 numeric digits, a hyphen, and then 4 numeric digits. The Canadian postal code must be of the form ANA NAN where A is any uppercase alphabetic character and N is a numeric digit from 0 to 9.  
0
 
LVL 7

Expert Comment

by:nisarkhan
ID: 13759535
Expression:  ^\d{5}-\d{4}|\d{5}|[A-Z]\d[A-Z] \d[A-Z]\d$
 
 
Sample Matches:  
44240|||44240-5555|||G3H 6A3
Sample Non-Matches:  
Ohio|||abc|||g3h6a3
Description:  This expression matches three different formats of postal codes: 5 digit US ZIP code, 5 digit US ZIP code + 4, and 6 digit alphanumeric Canadian Postal Code. The first one must be 5 numeric digits. The ZIP+4 must be 5 numeric digits, a hyphen, and then 4 numeric digits. The Canadian postal code must be of the form ANA NAN where A is any uppercase alphabetic character and N is a numeric digit from 0 to 9.
0
 

Author Comment

by:service2001
ID: 13764492
its not working... if i type the candian postal code still getting error
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question