1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Identification Validation |
4
|
|
|
* |
5
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
6
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
7
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
8
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
9
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
10
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
11
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
12
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
13
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
14
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
15
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
16
|
|
|
* |
17
|
|
|
* This software consists of voluntary contributions made by many individuals |
18
|
|
|
* and is licensed under the MIT license. |
19
|
|
|
* |
20
|
|
|
* @author Jacques Marneweck <[email protected]> |
21
|
|
|
* @copyright 2015-2017 Jacques Marneweck. All rights strictly reserved. |
22
|
|
|
* @license MIT |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
namespace Jacques\Validators; |
26
|
|
|
|
27
|
|
|
use Carbon\Carbon; |
28
|
|
|
|
29
|
|
|
class Gender |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* Checks that the users gender matches either f or m. |
33
|
|
|
* |
34
|
|
|
* gender is either: |
35
|
|
|
* - f - female |
36
|
|
|
* - m - gender |
37
|
|
|
* |
38
|
|
|
* @param string $gender |
39
|
|
|
* |
40
|
|
|
* @throws \InvalidArgumentException |
41
|
|
|
* |
42
|
|
|
* @return bool true if is valid else false |
43
|
|
|
*/ |
44
|
|
|
public static function is_valid($gender = null) |
45
|
|
|
{ |
46
|
|
|
if (is_null($gender)) { |
47
|
|
|
throw new \InvalidArgumentException('Please enter a valid gender.'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
if (empty($gender) || strlen($gender) > 1) { |
51
|
|
|
return false; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
if (is_numeric($gender)) { |
55
|
|
|
return false; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return in_array($gender, ['f', 'm']); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|