Cake\Localized\Validation\IrValidation::cc PHP Method

cc() public static method

Validation of Iran credit card numbers.
public static cc ( string $check ) : boolean
$check string The value to check.
return boolean Success.
    public static function cc($check)
    {
        $pattern = '/[0-9]{4}-?[0-9]{4}-?[0-9]{4}-?[0-9]{4}$/';
        return (bool) preg_match($pattern, $check);
    }

Usage Example

Beispiel #1
0
 /**
  * test the cc method of IrValidation
  *
  * @return void
  */
 public function testCc()
 {
     $this->assertTrue(IrValidation::cc('1111222233334444'));
     $this->assertTrue(IrValidation::cc('1111-2222-3333-4444'));
     $this->assertFalse(IrValidation::cc('teststring'));
     $this->assertFalse(IrValidation::cc('1111'));
     $this->assertFalse(IrValidation::cc('1111 2222 3333 4444'));
     $this->assertFalse(IrValidation::cc('111-122-223-333-444-4'));
 }