Cake\Localized\Validation\UsValidation::personId PHP Method

personId() public static method

Checks a social security number for The United States
public static personId ( string $check ) : boolean
$check string The value to check.
return boolean Success
    public static function personId($check)
    {
        $pattern = '/\\A\\b[0-9]{3}-[0-9]{2}-[0-9]{4}\\b\\z/i';
        return (bool) preg_match($pattern, $check);
    }

Usage Example

Example #1
0
 /**
  * test the ssn method of UsValidation
  *
  * @return void
  */
 public function testSsn()
 {
     $this->assertFalse(UsValidation::personId('11-33-4333'));
     $this->assertFalse(UsValidation::personId('113-3-4333'));
     $this->assertFalse(UsValidation::personId('111-33-333'));
     $this->assertTrue(UsValidation::personId('111-33-4333'));
 }