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

alphaNumeric() public static method

Also accepts latin numbers preventing potential problem until PHP becomes fully unicode compatible.
public static alphaNumeric ( string $check ) : boolean
$check string The value to check.
return boolean Success.
    public static function alphaNumeric($check)
    {
        $pattern = '/[^\\x{0600}-\\x{06FF}\\x{FB50}-\\x{FDFD}\\x{FE70}-\\x{FEFF}\\x{0750}-\\x{077F}0-9\\s\\x{200C}]+/u';
        return !preg_match($pattern, $check);
    }

Usage Example

Beispiel #1
0
 /**
  * test the alphaNumeric method of IrValidation
  *
  * @return void
  */
 public function testAlphaNumeric()
 {
     $this->assertTrue(IrValidation::alphaNumeric('آزمایش ۱۲۳۴۵۶۷۸۹۰'));
     $this->assertTrue(IrValidation::alphaNumeric('آزمایش 1234567890'));
     $this->assertTrue(IrValidation::alphaNumeric('هِمّت بُلَند دار کِه مَردانِ روزگار  اَز همّتِ بُلَند به جایی رسیده‌اَند'));
     $this->assertTrue(IrValidation::alphaNumeric('﷼'));
     $this->assertFalse(IrValidation::alphaNumeric('teststring'));
     $this->assertFalse(IrValidation::alphaNumeric('test1234567890'));
     $this->assertFalse(IrValidation::alphaNumeric('test آزمایش'));
 }