In a scenario where custom form validators require only Persian characters, the following code initially appeared promising:
var myregex = new Regex(@"^[\u0600-\u06FF]+$"); if (myregex.IsMatch(mytextBox.Text)) { args.IsValid = true; } else { args.IsValid = false; }
However, it failed to detect specific Persian characters (گ, چ, پ, ژ). This article delves into the issue and provides a solution.
[u0600-u06FF] and [آ-ی] are incorrect character ranges for Persian validation.
To ensure accuracy, the following ranges should be used:
Letters:
Numbers:
Vowels:
By utilizing the correct character ranges, rejecting invalid Persian characters can be achieved. Additionally, Farsi supports diacritics used in Arabic, but their inclusion is optional during validation.
The above is the detailed content of How to Create a Reliable Regex for Validating Persian Characters Only?. For more information, please follow other related articles on the PHP Chinese website!