Skip to content

Instantly share code, notes, and snippets.

@NimzyMaina
Last active November 22, 2023 08:31
Show Gist options
  • Save NimzyMaina/c32e6dc0ca9d6b83c6d28e3e25065677 to your computer and use it in GitHub Desktop.
Save NimzyMaina/c32e6dc0ca9d6b83c6d28e3e25065677 to your computer and use it in GitHub Desktop.
Regex to validate KRA PIN
<?php
$kra_regex = "/^[A]{1}[0-9]{9}[a-zA-Z]{1}$/";
$kra_pin = "A001234567J";
if(preg_match($kra_regex, $kra_pin)){
echo "Success! Valid KRA PIN";
}
else{
echo "Error! Invalid KRA PIN";
}
<?php
function isPinValid($pin)
{
return preg_match("/^[A]{1}[0-9]{9}[a-zA-Z]{1}$/", $pin);
}
$is_valid = isPinValid("A001234567J");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment