source: sandbox/webservice/api/rest/admin/CommonFunctions.php @ 7810

Revision 7810, 2.0 KB checked in by alexandrecorreia, 11 years ago (diff)

Ticket #2507 - Criado os resources para o módulo Expresso-Admin

  • Property svn:executable set to *
Line 
1<?php
2
3class CommonFunctions
4{
5        public function mascaraCPF($param)
6        {
7                $cpf = trim(preg_replace("/[^0-9]/", "", $param));
8
9                return preg_replace('/(\d{3})(\d{3})(\d{3})/','$1.$2.$3-',$cpf);
10        }
11
12        public function mascaraPhone($param)
13        {
14                $phone = trim(preg_replace("/[^0-9]/", "", $param));
15
16                return preg_replace('/(\d{2})(\d{4})(\d{4})/','($1)$2-$3',$phone);
17        }
18
19        public function validatePassword($param)
20        {
21                $sizePassword = strlen(trim($param));
22               
23                $numbers = strlen(preg_replace("/[^0-9]/", "", trim($param)));
24
25                $return['status'] = true;
26
27                if( (int)$sizePassword < 8 )
28                {
29                        $return["status"] = false;
30                        $return["msg"] = "you need a minimum of 8 characters for the password";
31                }
32                else
33                {
34                        if( (int)$numbers < 2 )
35                        {
36                                $return["status"] = false;
37                                $return["msg"] = "must have 2 numbers in the password";
38                        }
39                }       
40
41                return $return;
42        }
43
44        public function validateCharacters( $params )   
45        {
46                $search = trim(preg_replace("/[^a-z_0-9_A-Z_-_.]/", "", $params));
47
48                $return['status'] = true;
49
50                if( strtolower($search) != strtolower(trim($params)) )
51                {
52                        $return['status'] = false;
53                        $return['msg'] = "Field contains characters not allowed";
54                }
55
56                return $return;
57        }
58
59        public function validateCPF( $cpf )
60        {
61                $seqInvalid = array('11111111111','22222222222','33333333333',
62                                                        '44444444444','55555555555','66666666666',
63                                                        '77777777777','88888888888','99999999999',
64                                                        '00000000000', '12345678909');
65               
66                $cpf = trim(preg_replace("/[^0-9]/", "", $cpf));
67
68                if( strlen($cpf) != 11 )
69                        return False;
70
71                if( in_array( $cpf, $seqInvalid ) )
72                {
73                        return False;
74                }
75
76                $a = 0;
77               
78                for( $i = 0 ; $i < 9 ; $i++ )
79                {
80                        $a += ($cpf[$i]*(10 - $i));
81                }
82
83                $b = ($a % 11);
84               
85                $a = ( ($b > 1) ? (11 - $b) : 0);
86               
87                if( $a != $cpf[9] )
88                {
89                        return False;
90                }
91               
92                $a = 0;
93
94                for ( $i=0; $i < 10; $i++ )
95                {
96                        $a += ($cpf[$i]*(11 - $i));
97                }
98
99                $b = ($a % 11);
100
101                $a = (($b > 1) ? (11 - $b) : 0);
102               
103                if( $a != $cpf[10] )
104                {
105                        return False;
106                }
107
108                return True;
109        }
110}
111
112?>
Note: See TracBrowser for help on using the repository browser.