/var/www/(Del)hsihk.com/wp-content/plugins/woocommerce/includes/class-wc-validation.php


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
<?php
/**
 * Contains Validation functions
 *
 * @class         WC_Validation
 * @version        2.1.0
 * @package        WooCommerce/Classes
 * @category    Class
 * @author         WooThemes
 */
class WC_Validation {

    
/**
     * Validates an email using wordpress native is_email function
     *
     * @param   string    email address
     * @return  bool
     */
    
public static function is_email$email ) {
        return 
is_email$email );
    }

    
/**
     * Validates a phone number using a regular expression
     *
     * @param   string    phone number
     * @return  bool
     */
    
public static function is_phone$phone ) {
        if ( 
strlentrimpreg_replace'/[\s\#0-9_\-\+\(\)]/'''$phone ) ) ) > )
            return 
false;

        return 
true;
    }

    
/**
     * Checks for a valid postcode
     *
     * @param   string    postcode
     * @param    string    country
     * @return  bool
     */
    
public static function is_postcode$postcode$country ) {
        if ( 
strlentrimpreg_replace'/[\s\-A-Za-z0-9]/'''$postcode ) ) ) > )
            return 
false;

        switch ( 
$country ) {
            case 
"GB" :
                return 
self::is_GB_postcode$postcode );
            case 
"US" :
                 if ( 
preg_match"/^([0-9]{5})(-[0-9]{4})?$/i"$postcode ) )
                     return 
true;
                 else
                     return 
false;
            case 
"CH" :
                 if ( 
preg_match"/^([0-9]{4})$/i"$postcode ) )
                     return 
true;
                 else
                     return 
false;
            case 
"BR" :
                if ( 
preg_match"/^([0-9]{5,5})([-])?([0-9]{3,3})$/"$postcode ) )
                    return 
true;
                else
                    return 
false;
        }

        return 
true;
    }

    
/**
     * is_GB_postcode function.
     *
     * @author John Gardner
     * @access public
     * @param mixed $toCheck A postcode
     * @return bool
     */
    
public static function is_GB_postcode$toCheck ) {

        
// Permitted letters depend upon their position in the postcode.
        // http://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom#Validation
        
$alpha1 "[abcdefghijklmnoprstuwyz]";                          // Character 1
        
$alpha2 "[abcdefghklmnopqrstuvwxy]";                          // Character 2
        
$alpha3 "[abcdefghjkpstuw]";                                  // Character 3 == ABCDEFGHJKPSTUW
        
$alpha4 "[abehmnprvwxy]";                                     // Character 4 == ABEHMNPRVWXY
        
$alpha5 "[abdefghjlnpqrstuwxyz]";                             // Character 5 != CIKMOV

        // Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA
        
$pcexp[0] = '/^('.$alpha1.'{1}'.$alpha2.'{0,1}[0-9]{1,2})([0-9]{1}'.$alpha5.'{2})$/';

        
// Expression for postcodes: ANA NAA
        
$pcexp[1] =  '/^('.$alpha1.'{1}[0-9]{1}'.$alpha3.'{1})([0-9]{1}'.$alpha5.'{2})$/';

        
// Expression for postcodes: AANA NAA
        
$pcexp[2] =  '/^('.$alpha1.'{1}'.$alpha2.'[0-9]{1}'.$alpha4.')([0-9]{1}'.$alpha5.'{2})$/';

        
// Exception for the special postcode GIR 0AA
        
$pcexp[3] =  '/^(gir)(0aa)$/';

        
// Standard BFPO numbers
        
$pcexp[4] = '/^(bfpo)([0-9]{1,4})$/';

        
// c/o BFPO numbers
        
$pcexp[5] = '/^(bfpo)(c\/o[0-9]{1,3})$/';

        
// Load up the string to check, converting into lowercase and removing spaces
        
$postcode strtolower$toCheck );
        
$postcode str_replace (' '''$postcode);

        
// Assume we are not going to find a valid postcode
        
$valid false;

        
// Check the string against the six types of postcodes
        
foreach ( $pcexp as $regexp ) {

            if ( 
preg_match$regexp$postcode$matches ) ) {

                
// Load new postcode back into the form element
                
$toCheck strtoupper ($matches[1] . ' ' $matches [2]);

                
// Take account of the special BFPO c/o format
                
$toCheck str_replace'C/O''c/o '$toCheck );

                
// Remember that we have found that the code is valid and break from loop
                
$valid true;
                break;
            }
        }

        return 
$valid;
    }

    
/**
     * Format the postcode according to the country and length of the postcode
     *
     * @param   string    postcode
     * @param    string    country
     * @return  string    formatted postcode
     */
    
public static function format_postcode$postcode$country ) {
        
wc_format_postcode$postcode$country );
    }

    
/**
     * format_phone function.
     *
     * @access public
     * @param mixed $tel
     * @return string
     */
    
public static function format_phone$tel ) {
        
wc_format_phone_number$tel );
    }
}