Quick Search for:  in language:    
Form,Validation,check,supplied,Post,Code,corr
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
ASP/ VbScript Stats

 Code: 196,174. lines
 Jobs: 109. postings

 How to support the site

 
Sponsored by:

 
You are in:
 
Login


 

 


Latest Code Ticker for ASP/ VbScript.
Click here to see a screenshot of this code!Gallery Image with Zoom
By Marcelo Valle Franco on 1/12

(Screen Shot)

ASP Photo Competition
By Saul Bryan on 1/12


Execute DTS package
By Himadrish Laha on 1/12


Connecting to a MySQL with ADO, DAO and RDO
By Ahmed Magdy Ezzeldin on 1/11


Automatic Form Insertion To Database
By Yasar Bayar on 1/11


Click here to see a screenshot of this code!Find Closest Physical Location (based on zip code, etc)
By Mark Kahn on 1/11

(Screen Shot)

String --> SQL Search Query
By Mark Kahn on 1/11


Replace text/Numbers for Images...
By Kenneth Nilsson on 1/9


INSERT sentence generator
By Eitan Rousso on 1/8


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Affiliate Sites



 
 
   

UK Post Code Checker / Validator

Print
Email
 
VB icon
Submitted on: 9/23/2002 11:18:49 AM
By: David Morgan  
Level: Beginner
User Rating: By 1 Users
Compatibility:ASP (Active Server Pages), VbScript (browser/client side)

Users have accessed this code 1272 times.
 

 
     Use in Form Validation to check that a supplied UK Post Code is in the correct format, i.e. has letters and numbers in the correct places. Will format the post code correctly by return. Does not check that the Post Code exists.
 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!

    '**************************************
    ' for :UK Post Code Checker / Validator
    '**************************************
    None, but please advise if problem experienced
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

    '**************************************
    ' Name: UK Post Code Checker / Validator
    '     
    ' Description:Use in Form Validation to 
    '     check that a supplied UK Post Code is in
    '     the correct format, i.e. has letters and
    '     numbers in the correct places.
    Will format the post code correctly by return.
    Does Not check that the Post Code exists.
    ' By: David Morgan
    '
    ' Inputs:Alleged Post Code string to be 
    '     checked
    '
    ' Returns:True if the string conforms to
    '     the UK post code syntax.
    False if the String does Not conform To the UK post code syntax.
    '
    ' Assumes:Three Functions.
    1) Checks that a character is A - Z
    2) Checks that a character is 1 - 9
    3) Calls the above Functions as it works it's way through the supplied post code string.
    '
    ' Side Effects:The 'passed in' string wi
    '     ll be converted to upper case and have a
    '     space inserted in the correct place.
    '
    'This code is copyrighted and has    ' limited warranties.Please see http://w
    '     ww.Planet-Source-Code.com/vb/scripts/Sho
    '     wCode.asp?txtCodeId=7843&lngWId;=4    'for details.    '**************************************
    
    function IsValidPostCode(ByRef vPostCode)
    	Dim stChar
    	if Len(vPostCode) < 5 Then Exit function
    	vPostCode = Replace(vPostCode, " ", "")
    	Select Case Len(vPostCode)
    		Case 5 ' A1 1AA
    			if Not ValidateAlpha(Left(vPostCode, 1)) Then Exit function
    			if Not ValidateNumber(Mid(vPostCode, 2, 1)) Then Exit function
    			if Not ValidateNumber(Mid(vPostCode, 3, 1)) Then Exit function
    			if Not ValidateAlpha(Mid(vPostCode, 4, 1)) Then Exit function
    			if Not ValidateAlpha(Mid(vPostCode, 5, 1)) Then Exit function
    			vPostCode = UCase(Left(vPostCode, 2) & " " & Mid(vPostCode, 3))
    			IsValidPostCode = True
    			Exit function
    		Case 6 ' A11 1AA
    			if Not ValidateAlpha(Left(vPostCode, 1)) Then Exit function
    			if Not ValidateNumber(Mid(vPostCode, 2, 1)) And Not ValidateAlpha(Mid(vPostCode, 2, 1)) Then Exit function
    			if Not ValidateNumber(Mid(vPostCode, 3, 1)) Then Exit function
    			if Not ValidateNumber(Mid(vPostCode, 4, 1)) Then Exit function
    			if Not ValidateAlpha(Mid(vPostCode, 5, 1)) Then Exit function
    			if Not ValidateAlpha(Mid(vPostCode, 6, 1)) Then Exit function
    			vPostCode = UCase(Left(vPostCode, 3) & " " & Mid(vPostCode, 4))
    			IsValidPostCode = True
    			Exit function
    		Case 7 ' AA11 1AA
    			if Not ValidateAlpha(Left(vPostCode, 1)) Then Exit function
    			if Not ValidateAlpha(Mid(vPostCode, 2, 1)) Then Exit function
    			if Not ValidateNumber(Mid(vPostCode, 3, 1)) Then Exit function
    			if Not ValidateNumber(Mid(vPostCode, 4, 1)) Then Exit function
    			if Not ValidateNumber(Mid(vPostCode, 5, 1)) Then Exit function
    			if Not ValidateAlpha(Mid(vPostCode, 6, 1)) Then Exit function
    			if Not ValidateAlpha(Mid(vPostCode, 7, 1)) Then Exit function
    			vPostCode = UCase(Left(vPostCode, 4) & " " & Mid(vPostCode, 5))
    			IsValidPostCode = True
    			Exit function
    		Case Else
    			Exit function
    	End Select
    	vPostCode = UCase(vPostCode)
    End function
    function ValidateAlpha(vChar)
    	vChar = Asc(LCase(vChar))
    	if Not (vChar > 96 And vChar < 123) Then
    		Exit function
    	Else
    		ValidateAlpha = True
    	End if
    End function
    function ValidateNumber(vNumber)
    	if Not IsNumeric(vNumber) Then
    		Exit function
    	Else
    		vNumber = CLng(vNumber)
    		if vNumber < 1 Or vNumber > 9 Then
    			Exit function
    		Else
    			ValidateNumber = True
    		End if
    	End if		
    End function


Other 1 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
9/25/2002 7:34:58 AM:Vojimir Bato Kecman
Nice one, bit a long but...
Five for 
U.K. guy.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | ASP/ VbScript Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.