Completed
Push — dev ( c5c07e...787ff4 )
by Greg
03:32
created

Validate::text()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 9.568
c 0
b 0
f 0
cc 4
nc 2
nop 1
1
<?php
2
/**
3
 * /classes/DomainMOD/Validate.php
4
 *
5
 * This file is part of DomainMOD, an open source domain and internet asset manager.
6
 * Copyright (c) 2010-2020 Greg Chetcuti <[email protected]>
7
 *
8
 * Project: http://domainmod.org   Author: http://chetcuti.com
9
 *
10
 * DomainMOD is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
11
 * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
12
 * version.
13
 *
14
 * DomainMOD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
15
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License along with DomainMOD. If not, see
18
 * http://www.gnu.org/licenses/.
19
 *
20
 */
21
//@formatter:off
22
namespace DomainMOD;
23
24
class Validate
25
{
26
27
   public function tld($tld)
28
    {
29
        if(preg_match('/^[a-z\.\-]+$/i', $tld)) {
30
31
            return true;
32
33
        } else {
34
35
            return false;
36
37
        }
38
39
    }
40
41
   public function text($text)
42
    {
43
        /*
44
         * Strip whitespace from beginning and end of value
45
         * Make sure there's a value
46
         * Make sure the value isn't all whitespace
47
         * Make sure the value is 2 or more characters
48
         */
49
50
        $clean_text = trim($text);
51
52
        if($clean_text != '' && !ctype_space($clean_text) && strlen($clean_text) >= 2) {
53
54
            return true;
55
56
        } else {
57
58
            return false;
59
60
        }
61
62
    }
63
64
} //@formatter:on
65