Skip to content

Instantly share code, notes, and snippets.

@MakkiAbid
Last active March 20, 2021 13:28
Show Gist options
  • Save MakkiAbid/5c41057e190232ae3cec7601ffa2ede8 to your computer and use it in GitHub Desktop.
Save MakkiAbid/5c41057e190232ae3cec7601ffa2ede8 to your computer and use it in GitHub Desktop.
Pakistan's CNIC Regex PHP
// cnic check empty or valid
if (isset($_POST['cnic']) && !empty($_POST['cnic'])) {
if (preg_match('/^([0-9]{5})[\-]([0-9]{7})[\-]([0-9]{1})+/', $_POST['cnic'])) {
$cnic = clearInput($_POST['cnic']);
} else {
$cnic_error = '<p class="text-danger">Only numerics are allowed.</p>';
}
} else {
$cnic_error = '<p class="text-danger">Field is not to be empty.</p>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment