Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static function filterInput($value, $type) {
- if(!isset($type))
- return;
- switch($type)
- {
- case 'email': $pattern = '#^[\w-\._\+%]+@(?:[\w-]+\.)+[\w]{2,6}$#'; break;
- case 'password': $pattern = '#\b(?=.*[a-z]+)(?=.*[0-9]+).{6,20}\b#'; break;
- case 'username': $pattern = '#\b[a-z0-9\.]{8,32}\b#'; break;
- case 'phone': $pattern = '#^(\(\d+\)\s{0,1}){0,1}(\d+((\-|\s){0,1})\d+){0,}$#'; break;
- case 'number': $pattern = '#\b[\d]+\b#'; break;
- case 'only-string': $pattern = '#\b[a-z]+\b#i'; break;
- case 'only-string-lower': $pattern = '#\b[a-z]+\b#'; break;
- case 'only-string-upper': $pattern = '#\b[A-Z]+\b#'; break;
- case 'alnum': $pattern = '#\b[a-z0-9]+\b#i'; break;
- case 'word': $pattern = '#\b[a-z0-9_]+\b#'; break;
- }
- if(preg_match($pattern, $value)){
- #array_push(self::$_temporary, $value, $type, 'success');
- self::$serialized = self::serialize(array($value, $type, 'success'));
- }
- else {
- #array_push(self::$_temporary, $value, $type, 'failed');
- self::$serialized = self::serialize(array($value, $type, 'failed'));
- }
- return self::$that;
- }
- public static function setFilterValue() {
- $unserialized = array();
- $unserialized = self::unserialize(self::$serialized);
- if(!empty($unserialized)) {
- if(in_array('success', $unserialized)){
- array_push(self::$_filtered, array($unserialized[1] => $unserialized[0]));
- }
- else{
- array_push(self::$_unfiltered, array($unserialized[1] => $unserialized[0]));
- }
- }
- return;
- }
- /* VIEW */
- <?php
- if(isset($_POST['submit'])){
- RlxFilter::filterInput($_POST['test'], 'password')->setFilterValue();
- RlxFilter::filterInput($_POST['test1'], 'password')->setFilterValue();
- }
- if(sizeof(RlxFilter::$_unfiltered) > 0){
- foreach(RlxFilter::$_unfiltered as $key => $array){
- foreach($array as $k => $v){
- echo $k . ' - ' . $v . '<br>';
- }
- }
- }
- echo "<br><br>";
- if(sizeof(RlxFilter::$_filtered) > 0){
- foreach(RlxFilter::$_filtered as $key => $value) {
- echo ucfirst($key) . ' - ' . $value . '<br>';
- }
- }
- ?>
- <form action="" method="POST">
- <input type="text" name="test" />
- <input type="text" name="test1" />
- <input type="submit" name="submit" value="submit" />
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement