Forked from ShiponKarmakar/Email & Name Preg Match.php
Last active
October 8, 2022 12:01
-
-
Save TANVIRFAZLEY/1751cd42dacd3932155db7bdb758bc9c to your computer and use it in GitHub Desktop.
All Preg Metch PHP , Js ETC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if(!(preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", $email))){} | |
// User Name | |
if(!(preg_match("/^[A-Za-z][A-Za-z0-9]{5,21}$/", $username))){} | |
// Name | |
if(!(preg_match("/^(Mr|Mrs|Dr|Md)\.\ /", $name))){} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @param integer $country Country name | |
* @param integer $vat_number VAT number to test e.g. GB123 4567 89 | |
* @return integer -1 if country not included OR 1 if the VAT Num matches for the country OR 0 if no match | |
*/ | |
function checkVatNumber( $country, $vat_number ) { | |
switch($country) { | |
case 'Austria': | |
$regex = '/^(AT){0,1}U[0-9]{8}$/i'; | |
break; | |
case 'Belgium': | |
$regex = '/^(BE){0,1}[0]{0,1}[0-9]{9}$/i'; | |
break; | |
case 'Bulgaria': | |
$regex = '/^(BG){0,1}[0-9]{9,10}$/i'; | |
break; | |
case 'Cyprus': | |
$regex = '/^(CY){0,1}[0-9]{8}[A-Z]$/i'; | |
break; | |
case 'Czech Republic': | |
$regex = '/^(CZ){0,1}[0-9]{8,10}$/i'; | |
break; | |
case 'Denmark': | |
$regex = '/^(DK){0,1}([0-9]{2}[\ ]{0,1}){3}[0-9]{2}$/i'; | |
break; | |
case 'Estonia': | |
case 'Germany': | |
case 'Greece': | |
case 'Portugal': | |
$regex = '/^(EE|EL|DE|PT){0,1}[0-9]{9}$/i'; | |
break; | |
case 'France': | |
$regex = '/^(FR){0,1}[0-9A-Z]{2}[\ ]{0,1}[0-9]{9}$/i'; | |
break; | |
case 'Finland': | |
case 'Hungary': | |
case 'Luxembourg': | |
case 'Malta': | |
case 'Slovenia': | |
$regex = '/^(FI|HU|LU|MT|SI){0,1}[0-9]{8}$/i'; | |
break; | |
case 'Ireland': | |
$regex = '/^(IE){0,1}[0-9][0-9A-Z\+\*][0-9]{5}[A-Z]$/i'; | |
break; | |
case 'Italy': | |
case 'Latvia': | |
$regex = '/^(IT|LV){0,1}[0-9]{11}$/i'; | |
break; | |
case 'Lithuania': | |
$regex = '/^(LT){0,1}([0-9]{9}|[0-9]{12})$/i'; | |
break; | |
case 'Netherlands': | |
$regex = '/^(NL){0,1}[0-9]{9}B[0-9]{2}$/i'; | |
break; | |
case 'Poland': | |
case 'Slovakia': | |
$regex = '/^(PL|SK){0,1}[0-9]{10}$/i'; | |
break; | |
case 'Romania': | |
$regex = '/^(RO){0,1}[0-9]{2,10}$/i'; | |
break; | |
case 'Sweden': | |
$regex = '/^(SE){0,1}[0-9]{12}$/i'; | |
break; | |
case 'Spain': | |
$regex = '/^(ES){0,1}([0-9A-Z][0-9]{7}[A-Z])|([A-Z][0-9]{7}[0-9A-Z])$/i'; | |
break; | |
case 'United Kingdom': | |
$regex = '/^(GB){0,1}([1-9][0-9]{2}[\ ]{0,1}[0-9]{4}[\ ]{0,1}[0-9]{2})|([1-9][0-9]{2}[\ ]{0,1}[0-9]{4}[\ ]{0,1}[0-9]{2}[\ ]{0,1}[0-9]{3})|((GD|HA)[0-9]{3})$/i'; | |
break; | |
default: | |
return -1; | |
break; | |
} | |
return preg_match($regex, $vat_number); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment