Regex for Accepting Only Persian Characters
Validating input to ensure it contains only Persian characters can sometimes be challenging. While a range of codepoints may seem like an appropriate solution, it can inadvertently include unwanted characters.
The Unicode character set blocks for Arabic (0600–06FF) and Persian (PE) (0622–062F, 0631–064A, 064C–065F, 0670–067F, 0680–0683, 0685–0687, 0691–069A, 069C–069E) differ slightly. The commonly suggested regex [u0600-u06FF] covers all Arabic characters, including digits and some that are not used in Persian.
Solution
To accurately detect only Persian characters, consider the following character sets:
Combine these sets as needed to match specific requirements. Additionally, you may want to include Arabic Hamza (ء) in your character set.
Avoidance
Avoid using [u0600-u06FF] or [آ-ی], as they contain characters not used in Persian or excess characters, respectively.
The above is the detailed content of How to Create a Regex to Validate Only Persian Characters?. For more information, please follow other related articles on the PHP Chinese website!