This repository contains regular expression (regex) patterns for validating phone numbers, postal codes, VAT numbers and some common and critical in various applications patterns like date, currency etc. for European countries.
Below are the patterns for each European country, along with a brief description.
- Regex Patterns
- ๐ฆ๐ฉ Andorra
- ๐ฆ๐น Austria
- ๐ง๐ช Belgium
- ๐ง๐ฆ Bosnia and Herzegovina
- ๐ง๐ฌ Bulgaria
- ๐ญ๐ท Croatia
- ๐จ๐พ Cyprus
- ๐จ๐ฟ Czech Republic
- ๐ฉ๐ฐ Denmark
- ๐ช๐ช Estonia
- ๐ซ๐ฎ Finland
- ๐ซ๐ท France
- ๐ฉ๐ช Germany
- ๐ฌ๐ท Greece
- ๐ญ๐บ Hungary
- ๐ฎ๐ช Ireland
- ๐ฎ๐น Italy
- ๐ฑ๐ป Latvia
- ๐ฑ๐ฎ Liechtenstein
- ๐ฑ๐น Lithuania
- ๐ฑ๐บ Luxembourg
- ๐ฒ๐น Malta
- ๐ฒ๐ช Montenegro
- ๐ฒ๐จ Monaco
- ๐ณ๐ฑ Netherlands
- ๐ฒ๐ฐ North Macedonia
- ๐ณ๐ด Norway
- ๐ต๐ฑ Poland
- ๐ต๐น Portugal
- ๐ท๐ด Romania
- ๐ธ๐ฒ San Marino
- ๐ท๐ธ Serbia
- ๐ธ๐ฐ Slovakia
- ๐ธ๐ฎ Slovenia
- ๐ช๐ธ Spain
- ๐ธ๐ช Sweden
- ๐จ๐ญ Switzerland
- ๐ฌ๐ง United Kingdom
- Common Patterns
- Usage
- Pattern:
^\+376[0-9]{6}$
- Description: Andorran phone numbers start with +376, followed by 6 digits.
- Pattern:
^AD\d{3}$
- Description: Andorran postal codes start with "AD" followed by 3 digits.
- Not applicable as Andorra does not have a standard VAT number system like EU countries.
- Pattern:
^\+43[1-9][0-9]{3,12}$
- Description: Austrian phone numbers start with +43, followed by a non-zero digit and 3 to 12 more digits.
- Pattern:
^\d{4}$
- Description: Austrian postal codes are made up of 4 digits.
- Pattern:
^ATU\d{8}$
- Description: Austrian VAT numbers start with "ATU", followed by 8 digits.
- Pattern:
^\+32[1-9][0-9]{7,8}$
- Description: Belgian phone numbers typically start with +32, followed by a non-zero digit and then 7 to 8 additional digits. This pattern caters to both mobile and landline numbers.
- Pattern:
^\d{4}$
- Description: Belgian postal codes consist of 4 digits. This pattern matches a sequence of exactly four numerical digits.
- Pattern:
^BE0\d{9}$
- Description: Belgian VAT numbers start with "BE0", followed by 9 digits.
- Pattern:
^\+387[6][0-9]{7}$
- Description: Bosnian phone numbers typically start with +387, followed by a 6 (indicating a mobile number) and then 7 more digits. This pattern is tailored towards mobile numbers, as they are the most commonly used.
- Pattern:
^\d{5}$
- Description: Bosnian postal codes consist of 5 digits. This pattern matches a sequence of exactly five numerical digits.
- Bosnia and Herzegovina does not have a VAT number system similar to that of the European Union. For business and tax purposes, companies use a national ID number system. It's essential to consult local regulations or authorities for accurate and specific requirements regarding tax identification and reporting in Bosnia and Herzegovina.
- Pattern:
^\+359[1-9][0-9]{7,8}$
- Description: Bulgarian phone numbers begin with +359, followed by a non-zero digit and 7 to 8 additional digits.
- Pattern:
^\d{4}$
- Description: Bulgarian postal codes consist of 4 digits.
- Pattern:
BG\d{9,10}$
- Description: Bulgarian VAT numbers start with "BG", followed by 9 or 10 digits.
- Pattern:
^\+385[1-9][0-9]{7,8}$
- Description: Croatian phone numbers start with +385, followed by a non-zero digit and 7 to 8 more digits.
- Pattern:
^\d{5}$
- Description: Croatian postal codes are made up of 5 digits.
- Pattern:
^HR\d{11}$
- Description: Croatian VAT numbers start with "HR", followed by 11 digits.
- Pattern:
^\+357[2-9][0-9]{6,7}$
- Description: Cypriot phone numbers start with +357, followed by a digit between 2 and 9, and then 6 to 7 more digits.
- Pattern:
^\d{4}$
- Description: Cypriot postal codes consist of 4 digits. This pattern matches a sequence of exactly four numerical digits.
- Pattern:
^CY\d{8}L$
- Description: Cypriot VAT numbers start with "CY", followed by 8 digits and a final letter.
- Pattern:
^\+420[1-9][0-9]{8}$
- Description: Matches Czech phone numbers. Begins with +420 and is followed by 9 digits.
- Pattern:
^\d{3}\s?\d{2}$
- Description: Matches Czech postal codes, consisting of three digits, an optional space, and two more digits.
- Pattern:
^CZ\d{8,10}$
- Description: Czech VAT numbers start with "CZ", followed by 8 to 10 digits.
- Pattern:
^\+45[2-9][0-9]{7}$
- Description: Danish phone numbers begin with +45, followed by a digit between 2 and 9, and then 7 more digits. This pattern covers the standard 8-digit format after the country code.
- Pattern:
^\d{4}$
- Description: Danish postal codes consist of 4 digits. This pattern matches a sequence of exactly four numerical digits.
- Pattern:
^DK\d{8}$
- Description: Danish VAT numbers start with "DK", followed by 8 digits.
- Pattern:
^\+372[5-9][0-9]{6,7}$
- Description: Estonian phone numbers start with +372, followed by a digit between 5
- Pattern:
^\d{5}$
- Description: Estonian postal codes consist of 5 digits.
- Pattern:
^EE\d{9}$
- Description: Estonian VAT numbers start with "EE", followed by 9 digits.
- Pattern:
^\+358[1-9][0-9]{4,11}$
- Description: Finnish phone numbers start with +358, followed by a non-zero digit, and then 4 to 11 more digits.
- Pattern:
^\d{5}$
- Description: Finnish postal codes consist of 5 digits.
- Pattern:
^FI\d{8}$
- Description: Finnish VAT numbers start with "FI", followed by 8 digits.
- Pattern:
^\+33[1-9][0-9]{8}$
- Description: Matches French phone numbers. Begins with +33 and is followed by 9 digits.
- Pattern:
^\d{5}$
- Description: French postal codes are also 5 digits in length. This pattern matches a sequence of five numerical digits.
- Pattern:
^FR[A-HJ-NP-Z0-9]{2}\d{9}$
- Description: French VAT numbers start with "FR", followed by two characters (either digits or letters except O and I) and then 9 digits.
- Pattern:
^\+49[1-9][0-9]{1,14}$
- Description: Matches German phone numbers. Begins with +49 and is followed by 9 to 15 digits.
- Pattern:
^\d{5}$
- Description: German postal codes consist of 5 digits. This pattern matches a sequence of exactly five numerical digits.
- Pattern:
^DE\d{9}$
- Description: German VAT numbers start with "DE", followed by 9 digits.
- Pattern:
^\+30[2-9][0-9]{9}$
- Description: Matches Greek phone numbers. Begins with +30, followed by a digit from 2 to 9, and then 9 more digits.
- Pattern:
^\d{3}\s?\d{2}$
- Description: Matches Greek postal codes, consisting of three digits, an optional space, and two more digits.
- Pattern:
^EL\d{9}$
- Description: Greek VAT numbers start with "EL", followed by 9 digits.
- Pattern:
^\+36[1-9][0-9]{8}$
- Description: Hungarian phone numbers begin with +36, followed by a non-zero digit and 8 additional digits.
- Pattern:
^\d{4}$
- Description: Hungarian postal codes consist of 4 digits.
- Pattern:
^HU\d{8}$
- Description: Hungarian VAT numbers start with "HU", followed by 8 digits.
- Pattern:
^\+353[1-9][0-9]{6,9}$
- Description: Irish phone numbers begin with +353, followed by a non-zero digit, and then 6 to 9 more digits.
- Pattern:
^(D6W|[A-Z]{1}[0-9]{1,2}|[A-Z]{2}[0-9]{1,2}|[A-Z]{1}[0-9]{1}[A-Z]{1}|[A-Z]{2}[0-9]{1}[A-Z]{1})$
- Description: Irish postal codes (Eircode) are alphanumeric and follow several formats, including Dublin postal districts (e.g., D6W).
- Pattern:
^IE\d{7}[A-WY][A-I]?|IE[0-9+][A-Z+][0-9]{5}[A-WY]$
- Description: Irish VAT numbers start with "IE", followed by 7 digits and one or two letters. Variants include an additional character before the last digit for newer numbers.
- Pattern:
^\+39[0-9]{6,12}$
- Description: Matches Italian phone numbers, beginning with +39 and followed by 6 to 12 digits.
- Pattern:
^\d{5}$
- Description: Matches Italian postal codes, which consist of 5 digits.
- Pattern:
^IT\d{11}$
- Description: Italian VAT numbers start with "IT", followed by 11 digits.
- Pattern:
^\+371[2-9][0-9]{7}$
- Description: Latvian phone numbers begin with +371, followed by a digit between 2
- Pattern:
^LV-\d{4}$
- Description: Latvian postal codes start with "LV-" followed by 4 digits.
- Pattern:
^LV\d{11}$
- Description: Latvian VAT numbers start with "LV", followed by 11 digits.
- Pattern:
^\+423[0-9]{3,12}$
- Description: Liechtenstein phone numbers start with +423, followed by 3 to 12 digits.
- Pattern:
^\d{4}$
- Description: Liechtenstein postal codes are made up of 4 digits.
- Pattern:
^LI\d{5}$
- Description: Liechtenstein VAT numbers start with "LI", followed by 5 digits. The country uses a simpler system due to its smaller size.
- Pattern:
^\+370[6-9][0-9]{7}$
- Description: Lithuanian phone numbers start with +370, followed by a digit between 6 and 9, and then 7 more digits.
- Pattern:
^LT-\d{5}$
- Description: Lithuanian postal codes start with "LT-" followed by 5 digits.
- Pattern:
^LT\d{9,12}$
- Description: Lithuanian VAT numbers start with "LT", followed by 9 or 12 digits.
- Pattern:
^\+352[0-9]{3,11}$
- Description: Luxembourg phone numbers start with +352, followed by 3 to 11 digits.
- Pattern:
^\d{4}$
- Description: Luxembourg postal codes consist of 4 digits.
- Pattern:
^LU\d{8}$
- Description: Luxembourg VAT numbers start with "LU", followed by 8 digits.
- Pattern:
^\+356[0-9]{8}$
- Description: Malta phone numbers begin with +356, followed by 8 digits.
- Pattern:
^[A-Z]{3}\s?\d{2,4}$
- Description: Maltese postal codes consist of three letters followed by a space (optional) and 2 to 4 digits.
- Pattern:
^MT\d{8}$
- Description: Maltese VAT numbers start with "MT", followed by 8 digits.
- Pattern:
^\+382[6-9][0-9]{6,7}$
- Description: Montenegrin phone numbers typically start with +382, followed by a digit between 6 and 9, and then 6 to 7 more digits. This pattern covers both mobile and landline numbers.
- Pattern:
^\d{5}$
- Description: Montenegrin postal codes consist of 5 digits. This pattern matches a sequence of exactly five numerical digits.
- Pattern:
^ME\d{8}$
- Description: Montenegrin VAT numbers start with "ME", followed by 8 digits. Montenegro, not being an EU member, has its own VAT system.
- Pattern:
^\+377[0-9]{8,9}$
- Description: Monaco phone numbers begin with +377, followed by 8 to 9 digits.
- Pattern:
^980\d{2}$
- Description: Monaco postal codes start with 980 followed by two additional digits.
- Monaco does not have a distinct VAT number system and uses the French VAT system. Businesses in Monaco typically use French VAT numbers, which start with "FR", followed by two characters (either digits or letters except O and I) and then 9 digits.
- Pattern:
^\+31[0-9]{9}$
- Description: Matches Dutch phone numbers. Begins with +31 and is followed by 9 digits.
- Pattern:
^[1-9][0-9]{3}\s?[A-Z]{2}$
- Description: Matches Dutch postal codes, which consist of four digits followed by two letters.
- Pattern:
^NL\d{9}B\d{2}$
- Description: Dutch VAT numbers start with "NL", followed by 9 digits, "B", and 2 more digits.
- Pattern:
^\+389[2-9][0-9]{6,7}$
- Description: North Macedonian phone numbers begin with +389, followed by a digit between 2 and 9, and then 6 to 7 additional digits.
- Pattern:
^\d{4}$
- Description: North Macedonian postal codes consist of 4 digits. This pattern matches a sequence of exactly four numerical digits.
- Pattern:
^MK\d{13}$
- Description: North Macedonian VAT numbers start with "MK", followed by 13 digits. This format reflects the country's specific tax identification system.
- Pattern:
^\+47[2-9][0-9]{7,8}$
- Description: Norwegian phone numbers begin with +47, followed by a digit between 2 and 9, and then 7 to 8 additional digits.
- Pattern:
^\d{4}$
- Description: Norwegian postal codes consist of 4 digits.
- Pattern:
^NO\d{9}MVA$
- Description: Norwegian VAT numbers start with "NO", followed by 9 digits and end with "MVA" (which stands for "Merverdiavgift", the Norwegian term for VAT).
- Pattern:
^\+48[0-9]{9}$
- Description: Matches Polish phone numbers, beginning with +48 and followed by 9 digits.
- Pattern:
^\d{2}-\d{3}$
- Description: Matches Polish postal codes, which consist of two digits, a hyphen, and three more digits.
- Pattern:
^PL\d{10}$
- Description: Polish VAT numbers start with "PL", followed by 10 digits.
- Pattern:
^\+351[1-9][0-9]{8}$
- Description: Matches Portuguese phone numbers. Begins with +351 and is followed by 9 digits.
- Pattern:
^\d{4}-\d{3}$
- Description: Matches Portuguese postal codes, which consist of four digits, a hyphen, and three more digits.
- Pattern:
^PT\d{9}$
- Description: Portuguese VAT numbers start with "PT", followed by 9 digits.
- Pattern:
^\+40[1-9][0-9]{8,9}$
- Description: Romanian phone numbers start with +40, followed by a non-zero digit and 8 to 9 more digits.
- Pattern:
^\d{6}$
- Description: Romanian postal codes are made up of 6 digits.
- Pattern:
^RO\d{2,10}$
- Description: Romanian VAT numbers start with "RO", followed by between 2 and 10 digits.
- Pattern:
^\+378[0-9]{6,10}$
- Description: San Marino phone numbers start with +378, followed by 6 to 10 digits.
- Pattern:
^4789\d$
- Description: San Marino postal codes are "4789" followed by one digit.
- Pattern:
^SM\d{5}$
- Description: San Marino VAT numbers start with "SM", followed by 5 digits. Despite its size, San Marino has its own VAT system separate from Italy.
- Pattern:
^\+381[6-9][0-9]{6,8}$
- Description: Serbian phone numbers start with +381, followed by a digit between 6 and 9, and then 6 to 8 more digits.
- Pattern:
^\d{5}$
- Description: Serbian postal codes consist of 5 digits. This pattern matches a sequence of exactly five numerical digits.
- Pattern:
^RS\d{9}$
- Description: Serbian VAT numbers start with "RS", followed by 9 digits. Serbia, not being an EU member, has its own VAT registration system.
- Pattern:
^\+421[1-9][0-9]{8}$
- Description: Slovak phone numbers begin with +421, followed by a non-zero digit and 8 additional digits.
- Pattern:
^\d{3}\s?\d{2}$
- Description: Slovak postal codes have 5 digits, typically written with a space after the first three digits.
- Pattern:
^SK\d{10}$
- Description: Slovak VAT numbers start with "SK", followed by 10 digits.
- Pattern:
^\+386[1-9][0-9]{6,7}$
- Description: Slovenian phone numbers start with +386, followed by a non-zero digit and 6 to 7 additional digits.
- Pattern:
^\d{4}$
- Description: Slovenian postal codes consist of 4 digits.
- Pattern:
^SI\d{8}$
- Description: Slovenian VAT numbers start with "SI", followed by 8 digits.
- Pattern:
^\+34[6-9][0-9]{8}$
- Description: Matches Spanish phone numbers. Begins with +34, followed by a digit from 6 to 9, and then 8 more digits.
- Pattern:
^\d{5}$
- Description: Matches Spanish postal codes, which consist of 5 digits.
- Pattern:
^ES[A-Z]\d{7}[A-Z]$|^ES[A-Z][0-9]{7}[0-9A-Z]$|^ES[0-9]{8}[A-Z]$
- Description: Spanish VAT numbers start with "ES", followed by various formats including a letter, 7 digits, then a letter; or 8 digits then a letter.
- Pattern:
^\+46[0-9]{7,13}$
- Description: Matches Swedish phone numbers. Begins with +46 and is followed by 7 to 13 digits.
- Pattern:
^\d{3}\s?\d{2}$
- Description: Matches Swedish postal codes, consisting of three digits, an optional space, and two more digits.
- Pattern:
^SE\d{12}$
- Description: Swedish VAT numbers start with "SE", followed by 12 digits.
- Pattern:
^\+41[1-9][0-9]{8}$
- Description: Swiss phone numbers begin with +41, followed by a non-zero digit and 8 additional digits.
- Pattern:
^\d{4}$
- Description: Swiss postal codes consist of 4 digits.
- Pattern:
^CHE\d{9}MWST|TVA|IVA$
- Description: Swiss VAT numbers start with "CHE", followed by 9 digits and end with "MWST", "TVA", or "IVA", depending on the language region (German, French, or Italian for VAT).
- Pattern:
^\+44[1-9][0-9]{9,10}$
- Description: UK phone numbers start with +44, followed by a digit between 1 and 9, and then 9 to 10 additional digits. This pattern covers various formats including landlines, mobiles, and other services.
- Pattern:
^(GIR ?0AA|[A-Z]{1,2}[0-9]{1,2} ?[0-9][A-Z]{2})$
- Description: Matches UK postal codes.
- Pattern:
^GB\d{9}$|^GB\d{12}$|^GBGD\d{3}$|^GBHA\d{3}$
- Description: UK VAT numbers start with "GB", followed by either 9 digits, 12 digits, or specific codes like "GD" or "HA" for government departments and health authorities, respectively. Despite Brexit, the UK continues to use a VAT system similar to that of the EU.
European date formats typically use the day-month-year format, which differs from the month-day-year format used in the United States.
A regex pattern to match this format can look like this: ^(0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[012])/\d{4}$
This pattern checks for a valid day (01 to 31), month (01 to 12), and a 4-digit year. The 0? allows for dates to be written with or without a leading zero (e.g., "1/1/2024" or "01/01/2024").
To match amounts in euros, which might include commas for thousands separators and a period for the decimal point, you can use the following pattern: ^โฌ\s?\d{1,3}(,\d{3})*(\.\d{2})?$
This pattern supports amounts like "โฌ1,000.00", "โฌ100", and "โฌ 2,500.50". It ensures there is a euro symbol at the beginning, optional whitespace, followed by a number that may include commas and exactly two decimal places.
Vehicle registration codes in Europe can vary, but a simple pattern to match a generic format might be: ^[A-Z]{1,3}-\d{1,4}-[A-Z]{1,3}$
This pattern allows for 1 to 3 letters, followed by 1 to 4 digits, and then 1 to 3 letters again, all separated by dashes. This format matches some European vehicle registration codes but might need adjustments for specific countries.
To use regex patterns in PHP, we can use the preg_match
function.
Here's an example of how to validate a German phone number:
$pattern = '/^\+49[1-9][0-9]{1,14}$/';
$phoneNumber = '+491234567890';
if (preg_match($pattern, $phoneNumber)) {
echo "Valid German phone number.";
} else {
echo "Invalid German phone number.";
}
To use regex patterns in Python, we can use the re
module, which provides support for regular expressions.
Here's an example of how to validate a German phone number:
import re
# Regex pattern for a German phone number
pattern = r'^\+49[1-9][0-9]{1,14}$'
# Sample German phone number to test
phone_number = '+491234567890'
# Using the re.match function to check if the pattern matches the phone number
if re.match(pattern, phone_number):
print("Valid German phone number.")
else:
print("Invalid German phone number.")
In C#, we can use the System.Text.RegularExpressions
namespace to work with regex.
Here's an example of how to validate a German phone number:
using System;
using System.Text.RegularExpressions;
class Program
{
static void Main()
{
string pattern = @"^\+49[1-9][0-9]{1,14}$";
string phoneNumber = "+491234567890";
if (Regex.IsMatch(phoneNumber, pattern))
{
Console.WriteLine("Valid German phone number.");
}
else
{
Console.WriteLine("Invalid German phone number.");
}
}
}
In Java, regex functionalities are provided by the java.util.regex
package.
Here's an example of how to validate a German phone number:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
String pattern = "^\+49[1-9][0-9]{1,14}$";
String phoneNumber = "+491234567890";
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(phoneNumber);
if (m.find()) {
System.out.println("Valid German phone number.");
} else {
System.out.println("Invalid German phone number.");
}
}
}
Ruby has built-in support for regular expressions.
Here's an example of how to validate a German phone number:
pattern = /^\+49[1-9][0-9]{1,14}$/
phone_number = "+491234567890"
if phone_number.match(pattern)
puts "Valid German phone number."
else
puts "Invalid German phone number."
end
Here's an example of how to validate a German phone number:
const pattern = /^\+49[1-9][0-9]{1,14}$/;
const phoneNumber = '+491234567890';
if (pattern.test(phoneNumber)) {
console.log("Valid German phone number.");
} else {
console.log("Invalid German phone number.");
}
The regex patterns provided here are examples and may not cover all cases or nuances of phone number, postal code, VAT number and vehicle registration code formats. You would need to research and verify the patterns for each country.
Also, remember that phone number, postal code, VAT number and vehicle registration code formats can change, so it's good practice to periodically review and update these patterns.
Every contribution helps. If you have any questions, feel free to reach out.
This repository is unlicense[d], so feel free to fork.