View difference between Paste ID: dNb4vuDT and TdqKhj4A
SHOW: | | - or go back to the newest paste.
1
public static function filterInput($value, $type) {
2
        
3
        if(!isset($type))
4
            return;
5
        
6
        switch($type)
7
        {
8
            case 'email':               $pattern = '#^[\w-\._\+%]+@(?:[\w-]+\.)+[\w]{2,6}$#';               break;
9
            case 'password':            $pattern = '#\b(?=.*[a-z]+)(?=.*[0-9]+).{6,20}\b#';                 break;
10
            case 'username':            $pattern = '#\b[a-z0-9\.]{8,32}\b#';                                break;
11
            case 'phone':               $pattern = '#^(\(\d+\)\s{0,1}){0,1}(\d+((\-|\s){0,1})\d+){0,}$#';   break;
12
            case 'number':              $pattern = '#\b[\d]+\b#';                                           break;
13
            case 'only-string':         $pattern = '#\b[a-z]+\b#i';                                         break;
14
            case 'only-string-lower':   $pattern = '#\b[a-z]+\b#';                                          break;
15
            case 'only-string-upper':   $pattern = '#\b[A-Z]+\b#';                                          break;
16
            case 'alnum':               $pattern = '#\b[a-z0-9]+\b#i';                                      break;
17
            case 'word':                $pattern = '#\b[a-z0-9_]+\b#';                                      break;
18
        }
19
        
20
        if(preg_match($pattern, $value)){
21
            #array_push(self::$_temporary, $value, $type, 'success');
22
            self::$serialized = self::serialize(array($value, $type, 'success'));
23
        }
24
        else {
25
            #array_push(self::$_temporary, $value, $type, 'failed');
26
            self::$serialized = self::serialize(array($value, $type, 'failed'));
27
        }
28
        
29
        return self::$that;
30
    }
31
    
32
    public static function setFilterValue() {
33
        
34
        $unserialized = array();
35
        $unserialized = self::unserialize(self::$serialized);
36
        
37
        if(!empty($unserialized)) {
38
            
39
            if(in_array('success', $unserialized)){
40
                array_push(self::$_filtered, array($unserialized[1] => $unserialized[0]));
41
            }
42
            else{
43
                array_push(self::$_unfiltered, array($unserialized[1] => $unserialized[0]));
44
            }
45
            
46
        }
47
            
48
        return;
49
    }