IdanFitousi
IdanFitousi

Reputation: 63

Allow Hebrew letters in regex

I am working with C# and ASP.NET, and in my web application, I have a text box for registration where I allowed the user to input only letters using this regex:

Regex.IsMatch(to_check, @"^[a-zA-Z]+$")

I want to allow Hebrew letters, too. I would allow Unicode but I want only the Hebrew letters to be available.

Hope you could help, thanks!

Upvotes: 2

Views: 1836

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 627600

You can add the Unicode Hebrew named character class \p{IsHebrew} to your custom character class:

 Regex.IsMatch(to_check, @"^[a-zA-Z\p{IsHebrew}]+$")

Here is a full list of such named classes supported by .NET regex engine.

Upvotes: 6

Related Questions