-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added norwegian validation, updated README.md
- Loading branch information
Showing
3 changed files
with
35 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
* @author Emanuele "ToX" Toscano <[email protected]> | ||
* @license GNU General Public License; <https://www.gnu.org/licenses/gpl-3.0.en.html> | ||
* @link https://www.gov.uk/guidance/vat-eu-country-codes-vat-numbers-and-vat-in-other-languages | ||
* @link https://en.wikipedia.org/wiki/VAT_identification_number | ||
*/ | ||
class Validate | ||
{ | ||
|
@@ -96,6 +97,9 @@ public static function check(string $country, string $code): bool | |
case "NL": | ||
// 12 characters. The tenth character is always B | ||
return self::checkLength($code, 12, 12) && self::checkNetherlands($code); | ||
case "NO": | ||
// 9 characters. 12 when it contains the letters MVA | ||
return self::checkLength($code, 9, 12) && self::checkNorway($code); | ||
case "PL": | ||
// 10 characters. | ||
return self::checkLength($code, 10, 10) && self::numbersOnly($code); | ||
|
@@ -293,6 +297,27 @@ public static function checkNetherlands(string $code): bool | |
return true; | ||
} | ||
|
||
/** | ||
* Additional validations for Norway | ||
* | ||
* @param string $code Regional VAT code | ||
* | ||
* @return bool | ||
*/ | ||
public static function checkNorway(string $code): bool | ||
{ | ||
$return = false; | ||
|
||
// the string must be 9 digits, or 9 digits followed by MVA | ||
if (preg_match('/^[0-9]{9}$/i', $code)) { | ||
$return = true; | ||
} elseif (preg_match('/^[0-9]{9}[MVA]{3}$/i', $code)) { | ||
$return = true; | ||
} | ||
|
||
return $return; | ||
} | ||
|
||
/** | ||
* Additional validations for Spain | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters