All source code in ColdFusion Ask a ColdFusion Pro Discussion Forum Categories All jobs in ColdFusion
VAT,simple,script,checks,number,format,Europe
   Code/Articles � |  Newest/Best � |  Community � |  Jobs � |  Other � |  Goto � | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
ColdFusion Stats

 Code: 10,256. lines
 Jobs: 33. postings

 How to support the site

 
Sponsored by:
Quick Search for:  in language:    
You are in:
 
Login





Latest postings for ColdFusion.
Click here to see a screenshot of this code!StingTokenizer Example
By simple html code on 3/9

(Screen Shot)

Simple Print & Export to Excel via CFMX +
By CommandStation on 3/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!



 
 
   

Vat Number Format Checker

Print
Email
 
VB icon
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

Users have accessed this code 1475 times.
 
(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 chec
    //     ks the number format of European VAT num
    //     bers and makes sure they comply with the
    //     countries numbering/lettering format.
    // By: aMUSICsite
    //
    // Inputs:VAT country & VAT number.
    //
    // Returns:Valid VAT number or Invalid n
    //     umber and an error message explaining th
    //     e expected numbering format.
    //
    // Side Effects:I would not used this to
    //     guarantee a number is correct but it pro
    //     vides 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/Sh
    //     owCode.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 u
    //     pper 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#
    ---->

 
 Report Bad Submission
Use this form to notify 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!
Note:Not only will your feedback be posted, but an email will be sent to the code's author from the email account you registered on the site, so you can correspond directly.

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.
 
To post feedback, first please login.


 

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 | Games | Feedback | Customize | ColdFusion Home | Site Home | Other Sites | Open Letter from Moderators | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright� 1997-2010 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.