XF 1.5 Regex expression Arabic letters

Fethi.dz

Well-known member
Hello,

I was trying to today to test the (User Name Match Regular Expression) option on XF.

My forum is an Arabic one so I was trying to add a regex expression to allow the registration with Arabic letters only,

I used the following:

^[\u0621-\u064A]+$

Ref: https://en.wikipedia.org/wiki/Arabic_script_in_Unicode

I trying to register after applying the above expression but I got an error: (A server error occurred. Please try again later.)

Is the Unicode expressions not supported by XF1.5.x or there is an error in my code.

Appreciate you help guys.
 
So there are actually 2 problems here. First, \u isn't supported in PCRE unless it runs in JavaScript mode and this isn't exposed to PHP. In non-JS mode, you need \x{0621}. Second, this regex isn't actually running in UTF-8 mode. However, you can change that in the pattern itself.

As such, I believe this should work
Code:
(*UTF8)^[\x{0621}-\x{064A}]+$
Assuming your server supports Unicode character properties, this should work too and be more readable:
Code:
(*UTF8)^\p{Arabic}+$
 
Top Bottom