Created
November 15, 2020 16:17
-
-
Save alfintechcomputer/5853ab52daa25dd8ff5eb290bd9cf9f5 to your computer and use it in GitHub Desktop.
HTML Forms using PHP
This file contains 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 | |
// presence | |
$value = ''; | |
if(!isset($value) or empty($value)) { | |
echo 'fail'; | |
} | |
// string length | |
$value = ''; | |
$min = 2; | |
$max = 25; | |
if(strlen($value) < $min) { | |
echo 'fail - too small'; | |
} | |
if(strlen($value) > $max) { | |
echo 'fail - too big'; | |
} | |
// type | |
$value = ''; | |
if(!is_string($value)) { | |
echo 'fail - not a string'; | |
} | |
// set inclusion | |
$value = '7'; | |
$set = array('1', '2', '3', '4', '5', '6', '7', '8'); | |
if(!in_array($value, $set)) { | |
echo 'fail - not in the set'; | |
} | |
// format | |
$value = 'tom@jones.com'; | |
if(!preg_match('/@/', $value)) { | |
echo 'not a valid email'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment