Reputation: 43
I'm new in regular expression,write this regular expression:
if (Regex.IsMatch(txtName, @"^[آ-ی]$"))
{
int x = 0;
}
else
{
message += Environment.NewLine + "فیلد نام معتبر نمی باشد";
}
txtName value is :ابراهیم
but when run up if block,else segment run,why?thanks.
Upvotes: 0
Views: 67
Reputation: 634
You could use Named Blocks here for Arabic characters.
Example:
Regex.IsMatch(txtName, @"(\p{IsArabic}+(\s)?)+");
This will match the pattern of one or more Arabic characters followed by zero or one white-space characters one or more times. Tested as working with your input string.
Here's a more in depth reference from MSDN with additional examples.
Upvotes: 0
Reputation: 21400
@"^[آ-ی]$"
I don't think you want to mach only strings with a single char, so try
@"^[آ-ی]+$"
Upvotes: 1