Skip to content
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.

Commit

Permalink
refactored citizen identification to country specific methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkingshott committed Apr 26, 2020
1 parent 6e729f2 commit 23efc47
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
4 changes: 2 additions & 2 deletions resources/version.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 36 additions & 3 deletions src/Rules/CitizenIdentification.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public function passes($attribute, $value) : bool

case 'US':
case 'USA':
return preg_match("/^(?!000|666)[0-8][0-9]{2}-(?!00)[0-9]{2}-(?!0000)[0-9]{4}$/", $value) > 0;
return $this -> verifyUnitedStates($value);

case 'GB':
case 'GBR':
return preg_match("/^[A-CEGHJ-PR-TW-Z]{1}[A-CEGHJ-NPR-TW-Z]{1}[0-9]{6}[A-DFM]{0,1}$/", $value) > 0;
return $this -> verifyUnitedKingdom($value);

case 'FR':
case 'FRA':
return preg_match("/^[1,2][ ]?[0-9]{2}[ ]?[0,1,2,3,5][0-9][ ]?[0-9A-Z]{5}[ ]?[0-9]{3}[ ]?[0-9]{2}$/", $value) > 0;
return $this -> verifyFrance($value);

default:
return false;
Expand All @@ -57,4 +57,37 @@ public function message() : string
);
}



/**
* Verify whether the given value is a valid French citizen number.
*
**/
protected function verifyFrance($value) : bool
{
return preg_match("/^[1,2][ ]?[0-9]{2}[ ]?[0,1,2,3,5][0-9][ ]?[0-9A-Z]{5}[ ]?[0-9]{3}[ ]?[0-9]{2}$/", $value) > 0;
}



/**
* Verify whether the given value is a valid United Kingdom citizen number.
*
**/
protected function verifyUnitedKingdom($value) : bool
{
return preg_match("/^[A-CEGHJ-PR-TW-Z]{1}[A-CEGHJ-NPR-TW-Z]{1}[0-9]{6}[A-DFM]{0,1}$/", $value) > 0;
}



/**
* Verify whether the given value is a valid United States citizen number.
*
**/
protected function verifyUnitedStates($value) : bool
{
return preg_match("/^(?!000|666)[0-8][0-9]{2}-(?!00)[0-9]{2}-(?!0000)[0-9]{4}$/", $value) > 0;
}

}

0 comments on commit 23efc47

Please sign in to comment.