Important alert: (current site time 8/21/2014 7:48:59 AM EDT)
 

VB icon

Vat Number Format Checker

Email
Submitted on: 11/19/2009 8:53:50 AM
By: aMUSICsite  
Level: Advanced
User Rating: Unrated
Compatibility: Cold Fusion 4.5, Cold Fusion 5, Cold Fusion MX
Views: 10550
(About the author)
 
     A simple script that checks the number format of European VAT numbers and makes sure they comply with the countries numbering/lettering format.
 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
// for :Vat Number Format Checker
//**************************************
Use freely.
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: Vat Number Format Checker
// Description:A simple script that checks the number format of European VAT numbers and makes sure they comply with the countries numbering/lettering format.
// By: aMUSICsite
//
// Inputs:VAT country & VAT number.
//
// Returns:Valid VAT number or Invalid number and an error message explaining the expected numbering format.
//
// Side Effects:I would not used this to guarantee a number is correct but it provides a good first line defence against wrongly entered information.
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=142&lngWId=9//for details.//**************************************

<!----
100% free code, do what you like with it.
// Variables to send to this script.
<cfparam name="vatcountry" default="UK"> - The default VAT two letter character code for the country
<cfparam name="vatnumber" default="123456789"> - User supplied VAT number
// You may want to make the VAT number upper case before or after processing
<cfset vatnumber = "#ucase(vatnumber)#">
---->
<!---- // To start with generate a numbers only version of the VAT code ---->
<cfset numbersonly = "#rereplace("#vatnumber#", "[\D]", "", "all")#">
<!---- // Check each vat number by country and pass on either a FAIL with error message or a SUCCESS see comments at the bottom of the page for return variables ---->
<cfswitch expression="#vatcountry#">
<cfcase value ="AT">
<cfset numbersonly = "U#numbersonly#">
<cfif len(numbersonly) is 9><cfset validvat="1">
<cfset vatnumber = "#numbersonly#">
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for Austria should be 9 characters long in the following format: U12345678.">
</cfif>
</cfcase>
<cfcase value ="BE">
<cfif len(numbersonly) is 9 or len(numbersonly) is 10><cfset validvat="1">
<cfset vatnumber = "#numbersonly#">
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for Belgium should be 9 or 10 characters long in the following format: 1234567890.">
</cfif>
</cfcase>
<cfcase value ="BG">
<cfif len(numbersonly) is 9 or len(numbersonly) is 10><cfset validvat="1">
<cfset vatnumber = "#numbersonly#">
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for Bulgaria should be 9 or 10 characters long in the following format: 1234567890.">
</cfif>
</cfcase>
<cfcase value ="CY">
<cfif len(numbersonly) is 8 and asc(ucase(right(vatnumber, 1))) gte 65 and asc(ucase(right(vatnumber, 1))) lte 90>
<cfset validvat="1">
<cfset vatnumber = "#numbersonly##ucase(right(vatnumber, 1))#">
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for Cyprus should be 9 characters long and the last character should be a letter in the following format: 12345678X.">
</cfif>
</cfcase>
<cfcase value ="CZ">
<cfif len(numbersonly) gte 11 and len(numbersonly) lte 13>
<cfset numbersonly = (right(numbersonly, len(numbersonly)-3))>
<cfset validvat="1">
<cfelseif len(numbersonly) gte 8 or len(numbersonly) lte 10>
<cfset validvat="1">
<cfset vatnumber = "#numbersonly#">
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for the Czech Republic should be between 8 and 13 characters long in the following format: 1234567890123.">
</cfif>
</cfcase>
<cfcase value ="DK">
<cfif len(numbersonly) is 8>
<cfset validvat="1">
<cfset vatnumber = "#numbersonly#">
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for Denmark should be 8 characters long in the following format: 12345678.">
</cfif>
</cfcase>
<cfcase value ="EE">
<cfif len(numbersonly) is 9>
<cfset validvat="1">
<cfset vatnumber = "#numbersonly#">
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for Estonia should be 9 characters long in the following format: 123456789.">
</cfif>
</cfcase>
<cfcase value ="FI">
<cfif len(numbersonly) is 8>
<cfset validvat="1">
<cfset vatnumber = "#numbersonly#">
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for Finland should be 8 characters long in the following format: 12345678.">
</cfif>
</cfcase>
<cfcase value ="FR">
<cfif len(numbersonly) gte 9 and len(numbersonly) lte 11 and len(vatnumber) is 11>
<cfswitch expression="#len(numbersonly)#">
<cfcase value = "11"><cfset validvat="1"><cfset vatnumber = "#numbersonly#"></cfcase>
<cfcase value = "10">
<cfif (asc(ucase(left(vatnumber, 1))) gte 65 and asc(ucase(left(vatnumber, 1))) lte 90) or (asc(ucase(mid(vatnumber, 2, 1))) gte 65 and asc(ucase(mid(vatnumber, 2, 1))) lte 90)>
<cfset validvat="1"><cfset vatnumber = "#vatnumber#">
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for France should be 11 characters long in the following format: XX345678901.">
</cfif>
</cfcase>
<cfcase value = "9">
<cfif (asc(ucase(left(vatnumber, 1))) gte 65 and asc(ucase(left(vatnumber, 1))) lte 90) and (asc(ucase(mid(vatnumber, 2, 1))) gte 65 and asc(ucase(mid(vatnumber, 2, 1))) lte 90)>
<cfset validvat="1"><cfset vatnumber = "#vatnumber#">
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for France should be 11 characters long in the following format: XX345678901.">
</cfif>
</cfcase>
</cfswitch>
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for France should be 11 characters long in the following format: XX345678901.">
</cfif>
</cfcase>
<cfcase value ="DE">
<cfif len(numbersonly) is 9>
<cfset validvat="1">
<cfset vatnumber = "#numbersonly#">
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for Germany should be 9 characters long in the following format: 123456789.">
</cfif>
</cfcase>
<cfcase value ="EL">
<cfif len(numbersonly) is 9><cfset validvat="1">
<cfset vatnumber = "#numbersonly#">
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for Greece should be 9 characters long in the following format: 123456789.">
</cfif>
</cfcase>
<cfcase value ="HU">
<cfif len(numbersonly) is 8>
<cfset validvat="1">
<cfset vatnumber = "#numbersonly#">
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for Hungary should be 8 characters long in the following format: 12345678.">
</cfif>
</cfcase>
<cfcase value ="IE">
<cfif len(numbersonly) gte 6 and len(numbersonly) lte 8 and len(vatnumber) is 8>
<cfswitch expression="#len(numbersonly)#">
<cfcase value = "8"><cfset validvat="1"><cfset vatnumber = "#numbersonly#"></cfcase>
<cfcase value = "7"><cfif (asc(ucase(right(vatnumber, 1))) gte 65 and asc(ucase(right(vatnumber, 1))) lte 90)>
<cfset validvat="1"><cfset vatnumber = "#vatnumber#">
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for Ireland should be 8 characters long in the following format: 1X34567X.">
</cfif>
</cfcase>
<cfcase value = "6">
<cfif (asc(ucase(right(vatnumber, 1))) gte 65 and asc(ucase(right(vatnumber, 1))) lte 90) and (asc(ucase(mid(vatnumber, 2, 1))) gte 65 and asc(ucase(mid(vatnumber, 2, 1))) lte 90)>
<cfset validvat="1"><cfset vatnumber = "#vatnumber#">
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for Ireland should be 8 characters long in the following format: 1X34567X.">
</cfif>
</cfcase>
</cfswitch>
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for Ireland should be 8 characters long in the following format: 1X34567X.">
</cfif>
</cfcase>
<cfcase value ="IT">
<cfif len(numbersonly) is 11>
<cfset validvat="1">
<cfset vatnumber = "#numbersonly#">
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for Italy should be 11 characters long in the following format: 12345678901.">
</cfif>
</cfcase>
<cfcase value ="LV">
<cfif len(numbersonly) is 11>
<cfset validvat="1">
<cfset vatnumber = "#numbersonly#">
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for Latvia should be 11 characters long in the following format: 12345678901.">
</cfif>
</cfcase>
<cfcase value ="LT">
<cfif len(numbersonly) is 9 or len(numbersonly) is 12>
<cfset validvat="1">
<cfset vatnumber = "#numbersonly#">
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for Lithuania should be 9 or 12 characters long in the following format: 123456789 or 123456789012.">
</cfif>
</cfcase>
<cfcase value ="LU">
<cfif len(numbersonly) is 8><cfset validvat="1">
<cfset vatnumber = "#numbersonly#">
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for Luxembourg should be 8 characters long in the following format: 12345678.">
</cfif>
</cfcase>
<cfcase value ="MT">
<cfif len(numbersonly) is 8>
<cfset validvat="1">
<cfset vatnumber = "#numbersonly#">
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for Malta should be 8 characters long in the following format: 12345678.">
</cfif>
</cfcase>
<cfcase value ="NL">
<cfif len(numbersonly) is 11 and len(vatnumber) is 12 and ucase(mid(vatnumber, 10, 1)) is "B">
<cfset validvat="1">
<cfset vatnumber = "#ucase(vatnumber)#">
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for the Netherlands should be 12 characters long in the following format: 123456789B12.">
</cfif>
</cfcase>
<cfcase value ="PL">
<cfif len(numbersonly) is 10><cfset validvat="1">
<cfset vatnumber = "#numbersonly#">
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for Poland should be 10 characters long in the following format: 1234567890.">
</cfif>
</cfcase>
<cfcase value ="PT">
<cfif len(numbersonly) is 9 ><cfset validvat="1">
<cfset vatnumber = "#numbersonly#">
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for Portugal should be 9 characters long in the following format: 123456789.">
</cfif>
</cfcase>
<cfcase value ="RO">
<cfif len(numbersonly) gte 2 and len(numbersonly) lte 10><cfset validvat="1">
<cfset vatnumber = "#numbersonly#">
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for Romania should be between 2 and 10 characters long in the following format: 1234567890.">
</cfif>
</cfcase>
<cfcase value ="SK">
<cfif len(numbersonly) is 10><cfset validvat="1">
<cfset vatnumber = "#numbersonly#">
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for Slovakia should be 10 characters long in the following format: 1234567890.">
</cfif>
</cfcase>
<cfcase value ="SI">
<cfif len(numbersonly) is 8><cfset validvat="1">
<cfset vatnumber = "#numbersonly#">
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for Slovenia should be 8 characters long in the following format: 1234567890.">
</cfif>
</cfcase>
<cfcase value ="ES">
<cfif len(numbersonly) gte 7 and len(numbersonly) lte 9 and len(vatnumber) is 9>
<cfswitch expression="#len(numbersonly)#">
<cfcase value = "9"><cfset validvat="1"><cfset vatnumber = "#numbersonly#"></cfcase>
<cfcase value = "8">
<cfif (asc(ucase(left(vatnumber, 1))) gte 65 and asc(ucase(left(vatnumber, 1))) lte 90) or (asc(ucase(right(vatnumber, 1))) gte 65 and asc(ucase(right(vatnumber, 1))) lte 90)>
<cfset validvat="1"><cfset vatnumber = "#vatnumber#">
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for Spain should be 9 characters long in the following format: X2345678X.">
</cfif>
</cfcase>
<cfcase value = "7">
<cfif (asc(ucase(left(vatnumber, 1))) gte 65 and asc(ucase(left(vatnumber, 1))) lte 90) and (asc(ucase(right(vatnumber, 1))) gte 65 and asc(ucase(right(vatnumber, 1))) lte 90)>
<cfset validvat="1"><cfset vatnumber = "#vatnumber#">
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for Spain should be 9 characters long in the following format: X2345678X.">
</cfif>
</cfcase>
</cfswitch>
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for Spain should be 9 characters long in the following format: X2345678X.">
</cfif>
</cfcase>
<cfcase value ="SE">
<cfif len(numbersonly) is 12>
<cfset validvat="1">
<cfset vatnumber = "#numbersonly#">
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for Sweden should be 12 characters long in the following format: 123456789012.">
</cfif>
</cfcase>
<cfcase value ="GB">
<cfif len(numbersonly) is 9 or len(numbersonly) is 12>
<cfset validvat="1">
<cfset vatnumber = "#numbersonly#">
<cfelse>
<cfset validvat="0">
<cfset session.errormsg="The VAT code for the UK should be 9 or 12 characters long in the following format: 123456789012.">
</cfif>
</cfcase>
<cfdefaultcase><cfset validvat="1"></cfdefaultcase>
</cfswitch>
<!----
// Variables to pass back.
#validvat# - 1 = Good VAT number : 0 = Bad number
#session.errormsg# - Error message prompting for the correct format.
#vatnumber# - Vat number reformatted without the two digit country code at the beginning, the country code can be re-inserted using #vatcountry##vatnumber#
---->


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced 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


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.