Created
January 17, 2020 08:06
-
-
Save Vashy/69c8890840eb3a705beb41d822eeea05 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
function validateFiscalCode($fiscalCode) { | |
$regex = "/^[A-Z]{6}\d{2}[A-G]\d{2}[A-Z]\d{3}[A-Z]$/"; | |
return preg_match($regex, trim($fiscalCode, " ")); | |
} | |
function birthYear($fiscalCode) { | |
$birthYear = substr($fiscalCode, 6, 2); | |
if ($birthYear <= "99" && $birthYear > "25") | |
return intval("19" . $birthYear); | |
return intval("20" . $birthYear); | |
} | |
function isAdult($fiscalCode) { | |
return date("Y") - birthYear($fiscalCode) >= 18; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment