Cake\Localized\Validation\NoValidation::dob PHP Method

dob() public static method

Checks date of birth formal format for Norway (dd.mm.yyyy), afterwards checks if is a valid gregorian calendar date.
public static dob ( string $check ) : boolean
$check string the date of birth.
return boolean Success.
    public static function dob($check)
    {
        $pattern = '/^\\d{1,2}\\.\\d{1,2}\\.(\\d{2}|\\d{4})$/';
        $return = preg_match($pattern, $check);
        if (!$return) {
            return false;
        }
        $check = str_replace('.', ',', $check);
        $check = explode(',', $check, 3);
        return checkdate((int) $check[1], (int) $check[0], (int) $check[2]);
    }

Usage Example

Beispiel #1
0
 /**
  * test the dob method of NoValidation
  *
  * @return void
  */
 public function testDob()
 {
     // Examples from https://no.wikipedia.org/wiki/Dato
     $this->assertTrue(NoValidation::dob('10.8.1962'));
     $this->assertTrue(NoValidation::dob('10.08.1962'));
     $this->assertTrue(NoValidation::dob('10.8.62'));
     $this->assertTrue(NoValidation::dob('10.08.62'));
     $this->assertTrue(NoValidation::dob('02.08.1965'));
     $this->assertTrue(NoValidation::dob('2.8.1965'));
     $this->assertTrue(NoValidation::dob('02.08.65'));
     $this->assertTrue(NoValidation::dob('2.8.65'));
     $this->assertFalse(NoValidation::dob('10/8/1962'));
     $this->assertFalse(NoValidation::dob('10.24.1962'));
 }