CheckLib.class.php

Gesponsorde koppelingen

PHP script bestanden

  1. InputValidator.class.php
  2. ValidateForm.class.php
  3. CheckLib.class.php

« Lees de omschrijving en reacties

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
/**
 * @author Mark Eilander
 * @copyright 2008
 * @package onderzoeksinstrument
 * @version 1
 */
 
/**
 * CheckLib
 * @access public
 * @abstract
 */

abstract class CheckLib {

    /**
     * checkURL checks if the given string is an URL
     * @static
     * @access public
     * @param string $p_sURL
     * @return boolean True if string is correct URL, false if not
     */

    public static function checkURL($p_sURL) {
        if (preg_match('!^((ftp|(http(s)?))://)?(\.?([a-z0-9-]+))+\.[a-z]{2,6}(:[0-9]{1,5})?(/[a-zA-Z0-9.,;\?|\'+&%\$#=~_-]+)*$!i',$p_sURL) ) {
            return true;
        }
else {
            return false;
        }
    }

    /**
     * checkEmail checks if the given string is a valid Email address
     * @static
     * @access public
     * @author Dave Child
     * @link http://www.ilovejackdaniels.com/php/email-address-validation/ The email checking code
     * is mostly copied from this website. I have changed it to match the correct coding standard.
     * @param string $p_sEmail
     * @return boolean True if string is correct email address, false if not
     */

    public static function checkEmail($p_sEmail) {
        $p_sEmail = trim($p_sEmail);
        // First, we check that there's one @ symbol, and that the lengths are right
        if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $p_sEmail)) {
            // Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
            //throw new WebshopException('wrong nr of characters : '.$p_sEmail);

            return false;
        }

        // Split it into sections to make life easier
        $aEmail = explode("@", $p_sEmail);
        $aLocal = explode(".", $aEmail[0]);
        for ($i = 0; $i < sizeof($aLocal); $i++) {
            if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $aLocal[$i])) {
                //echo('name incorrect : "'.$aLocal[$i] . '" full: '.$p_sEmail.'<br />');
                return false;
            }
        }

        if (!ereg("^\[?[0-9\.]+\]?$", $aEmail[1])) {
            // Check if domain is IP. If not, it should be valid domain name
            $aDomain = explode(".", $aEmail[1]);
            if (sizeof($aDomain) < 2) {
                //echo('domains wrong : '.$p_sEmail.'<br />');
                return false; // Not enough parts to domain
            }
            for ($i = 0; $i < sizeof($aDomain); $i++) {
                if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $aDomain[$i])) {
                    //echo('Domain part wrong ['.$i.']: '.$p_sEmail.'<br />');
                    return false;
                }
            }
        }

        return true;    
    }
    
    /**
     * checkDutchZipcode checks if the given string is a valid dutch zipcode
     * @static
     * @access public
     * @param string $p_sZipcode
     * @return boolean True if string is correct zipcode, false if not
     */

    public static function checkDutchZipcode($p_sZipcode) {
        if (preg_match("/^\d{4}[\s-]?[a-zA-Z]{2}$/",$p_sZipcode) ) {
            return true;
        }
else {
            return false;
        }
    }


    /**
     * checkPhoneNumber checks if the given string is a valid dutch phonenumber
     * @static
     * @access public
     * @param string $p_sPhone
     * @return boolean True if string is correct phonenumber, false if not
     */

    public static function checkPhoneNumber($p_sPhone) {
        if (preg_match("/^[0-9\-]{11}$/",$p_sPhone) ) {
            return true;
        }
else {
            return false;
        }
    }


    /**
     * checkAccountNumber checks if the given string is a valid dutch bank accountnumber
     * @static
     * @access public
     * @param string $p_sAccount
     * @return boolean True if string is correct phonenumber, false if not
     */

    public static function checkAccountNumber($p_sAccount) {
        if (preg_match("/^[1-9][0-9]{3,}$/",$p_sAccount) ) {
            return true;
        }
else {
            return false;
        }
    }

    
    /**
     * checkPlainText    checks if the given string contains only normal input characters
     *
     * @static
     * @access public
     * @param string    $p_sText
     * @return boolean True if string contains only plain characters
     */

    public static function checkPlainText($p_sText) {
        if (preg_match("/[a-zA-Z\d\.\s\-]*$/",$p_sText) ) {
            return true;
        }
else {
            return false;
        }
    }


    /**
     * checkAlphaText    checks if the given string contains only normal input characters and NO numbers
     * we accept '.', '-' and whitespaces
     * @static
     * @access public
     * @param string    $p_sText
     * @return boolean True if string contains only plain characters
     */

    public static function checkAlphaText($p_sText) {
        if (preg_match("/[a-zA-Z\.\s\-]*$/",$p_sText) ) {
            return true;
        }
else {
            return false;
        }
    }


    /**
     * checkUserDefinedText    checks if the given string matches the given regular expression
     *
     * @static
     * @access public
     * @param string    $p_sExpression
     * @param string    $p_sText The text to check
     * @return boolean True if string contains only plain characters
     */

    public static function checkUserDefinedText($p_sExpression, $p_sText) {
        if (preg_match($p_sExpression, $p_sText) ) {
            return true;
        }
else {
            return false;
        }
    }
}

?>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.