Skip to content

Instantly share code, notes, and snippets.

@vbaert
Last active December 20, 2015 04:18
Show Gist options
  • Save vbaert/6069494 to your computer and use it in GitHub Desktop.
Save vbaert/6069494 to your computer and use it in GitHub Desktop.
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