-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathValidate.php
47 lines (39 loc) · 1020 Bytes
/
Validate.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
<?php
class Validate
{
/**
* Validates an e-mail address
*
* @param string $email e-mail address
* @param boolean $checkRegistered check if the e-mnail address is already registered
* @param boolean $checkBanned check if the e-mail address has been banned
*
* @return boolean success
*/
static function email( &$email )
{
$email = strtolower($email);
if( filter_var($email, FILTER_VALIDATE_EMAIL) === false )
return false;
return true;
}
/**
* Validates a phone number
*
* @param int $phone phone number
* @param boolean $null_allowed true if the phone number is allowed to be empty
* @param string $type phone number type
*
* @return int updated phone number
*/
static function phone( &$phone, $null_allowed = true )
{
if ($phone == '' && $null_allowed) return true;
$phone = preg_replace("/[[:^digit:]]/", '', $phone);
if( strlen($phone) < 10 || !is_numeric($phone) )
return false;
if( strlen( $phone ) == 10 )
$phone = '1' . $phone;
return true;
}
}