Skip to content

Instantly share code, notes, and snippets.

@Vashy
Created January 17, 2020 08:06
Show Gist options
  • Save Vashy/69c8890840eb3a705beb41d822eeea05 to your computer and use it in GitHub Desktop.
Save Vashy/69c8890840eb3a705beb41d822eeea05 to your computer and use it in GitHub Desktop.
<?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