Home > Backend Development > C++ > How to Create a Regex to Validate Only Persian Characters?

How to Create a Regex to Validate Only Persian Characters?

Susan Sarandon
Release: 2025-01-02 17:03:39
Original
169 people have browsed it

How to Create a Regex to Validate Only Persian Characters?

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:

  • Letters: ^[آابپتثجچحخدذرزژسشصضطظعغفقکگلمنوهی] $
  • Numbers: ^[۰۱۲۳۴۵۶۷۸۹] $
  • Vowels: [ ‬ٌ ‬ًّ ‬َ ‬ِ ‬ُ ‬ْ ‬]

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template