Skip to content

Instantly share code, notes, and snippets.

@alfintechcomputer
Created November 15, 2020 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alfintechcomputer/5853ab52daa25dd8ff5eb290bd9cf9f5 to your computer and use it in GitHub Desktop.
Save alfintechcomputer/5853ab52daa25dd8ff5eb290bd9cf9f5 to your computer and use it in GitHub Desktop.
HTML Forms using PHP
<?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