Skip to content

Instantly share code, notes, and snippets.

@wesamly
Last active February 23, 2021 13:53
Show Gist options
  • Save wesamly/37f3f64c2cd3fb2f9056cd27ae24796f to your computer and use it in GitHub Desktop.
Save wesamly/37f3f64c2cd3fb2f9056cd27ae24796f to your computer and use it in GitHub Desktop.
Libyan National Number Regex
<?php
/**
* Total Length: 12 digits
* [1][2002][0012345]
* | | |
* | | -> Random: 7 digits
* | -> Birth Year: 4 digits
* -> Gender 1 male / 2 female: 1 digit
*/
$value = '120020012345';
//from 1900 - 2099
$pattern = '/^(1|2)(19|20)[0-9]{2}[0-9]{7}$/';
if (preg_match($pattern, $value)) {
echo 'Valid NID Number';
} else {
echo 'Invalid NID Number';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment