Last active
November 3, 2021 02:46
-
-
Save rahman541/4a7965f070798a5dade0 to your computer and use it in GitHub Desktop.
IC Number input validation on server side (PHP) using Regular Expression (Regex)
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 | |
$ic = "123456-11-1111"; //default ic if not set | |
if(isset($_POST["ic"])){ | |
$ic = $_POST["ic"]; | |
} | |
$regex = '/^[0-9]{6}-[0-9]{2}-[0-9]{4}$/'; | |
if (preg_match($regex, $ic)) { | |
echo 'Valid'; | |
} else { | |
echo 'Invalid'; | |
} | |
echo " IC Number"; | |
?> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>IC Validator</title> | |
</head> | |
<body> | |
<form method="POST"> | |
<input type="text" name="ic" placeholder="IC eg. 990104-07-5555"> | |
<input type="submit"> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment