| @@ 24-62 (lines=39) @@ | ||
| 21 | /** |
|
| 22 | * Validate the possibility of a mobile number being a valid Namibian Mobile Number. |
|
| 23 | */ |
|
| 24 | \Valitron\Validator::addRule('na_mobile_number', function ($field, $value, array $params, array $fields) { |
|
| 25 | $msisdn = str_replace(array(' ', '-', '(', ')'), '', $value); |
|
| 26 | $country = 'NA'; |
|
| 27 | ||
| 28 | $phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance(); |
|
| 29 | try { |
|
| 30 | $phoneNumberProto = $phoneUtil->parse($msisdn, $country); |
|
| 31 | } catch (\libphonenumber\NumberParseException $e) { |
|
| 32 | return false; |
|
| 33 | } |
|
| 34 | ||
| 35 | if (!$phoneUtil->isValidNumber($phoneNumberProto)) { |
|
| 36 | return false; |
|
| 37 | } |
|
| 38 | ||
| 39 | if ( |
|
| 40 | !in_array( |
|
| 41 | $phoneUtil->getNumberType($phoneNumberProto), |
|
| 42 | [ |
|
| 43 | 1, |
|
| 44 | 2, |
|
| 45 | ] |
|
| 46 | ) |
|
| 47 | ) { |
|
| 48 | return false; |
|
| 49 | } |
|
| 50 | ||
| 51 | if ( |
|
| 52 | !is_null($country) |
|
| 53 | ) { |
|
| 54 | if ($country == $phoneUtil->getRegionCodeForNumber($phoneNumberProto)) { |
|
| 55 | return true; |
|
| 56 | } |
|
| 57 | ||
| 58 | return false; |
|
| 59 | } |
|
| 60 | ||
| 61 | return true; |
|
| 62 | }, 'must be a valid Namibian Mobile Number'); |
|
| 63 | ||
| 64 | /** |
|
| 65 | * Validate the possibility of the South African Identity Number beng a valid South |
|
| @@ 101-139 (lines=39) @@ | ||
| 98 | /** |
|
| 99 | * Validate the possibility of a mobile number being a valid South African Mobile Number. |
|
| 100 | */ |
|
| 101 | \Valitron\Validator::addRule('za_mobile_number', function ($field, $value, array $params, array $fields) { |
|
| 102 | $msisdn = str_replace(array(' ', '-', '(', ')'), '', $value); |
|
| 103 | $country = 'ZA'; |
|
| 104 | ||
| 105 | $phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance(); |
|
| 106 | try { |
|
| 107 | $phoneNumberProto = $phoneUtil->parse($msisdn, $country); |
|
| 108 | } catch (\libphonenumber\NumberParseException $e) { |
|
| 109 | return false; |
|
| 110 | } |
|
| 111 | ||
| 112 | if (!$phoneUtil->isValidNumber($phoneNumberProto)) { |
|
| 113 | return false; |
|
| 114 | } |
|
| 115 | ||
| 116 | if ( |
|
| 117 | !in_array( |
|
| 118 | $phoneUtil->getNumberType($phoneNumberProto), |
|
| 119 | [ |
|
| 120 | 1, |
|
| 121 | 2, |
|
| 122 | ] |
|
| 123 | ) |
|
| 124 | ) { |
|
| 125 | return false; |
|
| 126 | } |
|
| 127 | ||
| 128 | if ( |
|
| 129 | !is_null($country) |
|
| 130 | ) { |
|
| 131 | if ($country == $phoneUtil->getRegionCodeForNumber($phoneNumberProto)) { |
|
| 132 | return true; |
|
| 133 | } |
|
| 134 | ||
| 135 | return false; |
|
| 136 | } |
|
| 137 | ||
| 138 | return true; |
|
| 139 | }, 'must be a valid South African Mobile Number'); |
|
| 140 | } |
|
| 141 | } |
|
| 142 | ||