Search code examples
phpregexarabicphpbb3

Arabic Alphanumeric with spaces only regex


I want to know the equivalent of the following, but for Arabic alphabet only:

$regex = '[A-Za-z0-9-[\]_+ ]+'

I tried:

$regex = '[ا-ئ0-9 ]+';

In which the first Arabic letter ا and the last one ئ. However, I have got the following error:

[phpBB Debug] PHP Warning: 
in file [ROOT]/includes/functions_user.php on line 1505: preg_match():
Compilation failed: range out of order in character class at offset 6

Solution

  • You can check if your Regex flavour supports \p{Arabic} or \p{InArabic}

    try:

    $regex = '[\p{Arabic}\d-\[\]_+ ]+'