View difference between Paste ID: uGGZeXAm and dNb4vuDT
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-
    }
49+
50
51
52
53
/* VIEW */
54
55
<?php
56
    
57
    if(isset($_POST['submit'])){
58
        RlxFilter::filterInput($_POST['test'], 'password')->setFilterValue();
59
        RlxFilter::filterInput($_POST['test1'], 'password')->setFilterValue();
60
    }
61
    
62
    if(sizeof(RlxFilter::$_unfiltered) > 0){
63
        foreach(RlxFilter::$_unfiltered as $key => $array){
64
            foreach($array as $k => $v){
65
                echo $k . ' - ' . $v . '<br>';
66
            }
67
        }
68
    }
69
    echo "<br><br>";
70
    if(sizeof(RlxFilter::$_filtered) > 0){
71
        foreach(RlxFilter::$_filtered as $key => $value) {
72
            echo ucfirst($key) . ' - ' . $value . '<br>';
73
        }
74
    }
75
    ?>
76
    <form action="" method="POST">
77
    <input type="text" name="test" />
78
    <input type="text" name="test1" />
79
    <input type="submit" name="submit" value="submit" />
80
    </form>