Cake\Localized\Validation\FrValidation::postal PHP Method

postal() public static method

Checks a postal code for France.
public static postal ( string $check ) : boolean
$check string The value to check.
return boolean Success.
    public static function postal($check)
    {
        $pattern = '/^\\d{5}$/';
        if ((bool) preg_match($pattern, $check)) {
            $value = intval($check);
            return $value >= 1001 && $value <= 99138;
        }
        return false;
    }

Usage Example

Beispiel #1
0
 /**
  * test the postal method of FrValidation
  *
  * @return void
  */
 public function testPostal()
 {
     $this->assertTrue(FrValidation::postal('01001'));
     $this->assertTrue(FrValidation::postal('14000'));
     $this->assertTrue(FrValidation::postal('75001'));
     $this->assertTrue(FrValidation::postal('13200'));
     $this->assertTrue(FrValidation::postal('97500'));
     $this->assertTrue(FrValidation::postal('99138'));
     $this->assertFalse(FrValidation::postal('1400'));
     $this->assertFalse(FrValidation::postal('14 000'));
     $this->assertFalse(FrValidation::postal('00000'));
     $this->assertFalse(FrValidation::postal('01000'));
     $this->assertFalse(FrValidation::postal('99139'));
 }