Scripts
Sentry
Update 04-02: - Email-verificatie toegevoegd - Minimaal aantal tekens toegevoegd: validateMinCharCount( $input, ); - Maximaal aantal tekens toegevoegd: validateMaxCharCount( $input, ); Simpel, klein, lichtgewicht class die (tot nu toe) controleert of een bepaalde input alleen cijfers, of cijfers en letters bevat. Uitbreiding is mogelijk, kom maar op met suggesties! Controle gaat gemakkelijk als volgt (voorbeeld):
sentry
<?php
##
## SENTRY_CLASS.PHP
## Checking all user input
## By Dave Bronckers
class Sentry{
## SENTRY CONFIGURATION
## 1 = enabled
## 0 = disabled
private $enable = 1;
## NO EDITTING BEHIND
## THIS COMMENT
public function __construct(){
if( $this->enable == 0){
$this->__destruct();
}
}
public function validateNum( $input ){
if( !is_numeric( $input )){
throw new Exception( 'Invoer is niet numeriek.' );
}
}
public function validateMix( $input ){
if(!preg_match( '/^[a-z0-9]+$/', $input)){
throw new Exception( 'Gebruikersgegevens zijn niet correct.' );
}
}
public function validateString( $input ){
if(!preg_match( '/^[a-z0-9]+$/', $input)){
throw new Exception( 'Invoer is niet alfabetisch.' );
}
}
public function validateEmail( $input ){
if(!preg_match( '/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)*\.([a-zA-Z]{2,6})$/', $input )){
throw new Exception( 'Invoer bevat verboden tekens.');
}
}
public function validateMinCharCount( $input, $limit ){
if(strlen($input) < $limit){
throw new Exception( 'Invoer bevat onvoldoende tekens. Minimaal ' . $limit . ' tekens vereist.');
}
}
public function validateMaxCharCount( $input, $limit ){
if(strlen($input) > $limit){
throw new Exception( 'Invoer bevat teveel tekens. Maximaal ' . $limit . ' tekens toegestaan.');
}
}
}
?>
Reacties
0