Last active
December 20, 2015 04:18
-
-
Save vbaert/6069494 to your computer and use it in GitHub Desktop.
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
class FormChecker { | |
private $postdata; | |
function __construct($POST) { | |
$this->setPostData($POST); | |
} | |
private function setPostData($POST) { | |
if(is_array($POST)) { | |
foreach($POST as $key => $value) { | |
$this->postdata[$key] = trim($value); | |
} | |
} else $this->postdata = array(); | |
} | |
private function checkPostData($key, $expression, $length = false) { | |
if(!isset($this->postdata[$key])) return 0; | |
$regexp = $length ? '/'.$expression.'{'.$length.'}/' : '/'.$expression.'/'; | |
$check = preg_match($regexp, $this->postdata[$key]); | |
var_dump($check); | |
return $check ? 1 : 0; | |
} | |
public function isNumeric($key) { | |
$c = $this->checkPostData($key, '^[0-9]{1,}$'); | |
return $c; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment