3

I need an expression that can accept only Hebrew letters and at least one space char.

I tried this for Hebrew letters, but it doesn't match sentences with Hebrew text and spaces:

result = Regex.IsMatch(txtName.Text, @"[\u05D0\u05D1\u05D2\u05D3\u05D4\u05D5\u05D6\u05D7\u05D8\u05D9\u05DA\u05DB\u05DC\u05DD\u05DE\u05DF\u05E0\u05E1\u05E2\u05E3\u05E4\u05E5\u05E6\u05E7\u05E8\u05E9\u05EA]");

How can I represent all the Hebrew letters and at least one space char in regEx?

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
user2922456
  • 391
  • 4
  • 10
  • 24
  • Did you try anything? A small suggestion: if you tried anything...post it, you won't be downvoted! Hebrew characters UNICODE range is from `0x0590` to `0x05ff`, spaces may be represented by `\s` and with `+` you'll require one or more of them...this regex should match it: `[\u0590-\u05ff]+\s+` – Adriano Repetti Sep 26 '14 at 14:15
  • 1
    Side note: "tried a lot" is not really showing any effort. Even single sample line of code showing what you've actually tried would likely avoid all downwotes. Same goes "searched a lot" if you ever decide to add that to your posts - show your search query/best result you found and it is clear what is wrong (for all people would know you are searching on http://dinsney.com). – Alexei Levenkov Sep 26 '14 at 14:22
  • 1
    Take a look at http://stackoverflow.com/a/9242066/1043380 – gunr2171 Sep 26 '14 at 14:23
  • @AdrianoRepetti - question looks real now - consider posting your comment as answer, also gunr2171 suggestion shows much better approach - should be duplicate (but I've used up my vote already :) ) – Alexei Levenkov Sep 26 '14 at 14:24
  • @AdrianoRepetti I tried what you suggest, it works only if I have one word. If I enter a sentence to check and the other words in english the flag dosent 'rise up'..How to fix it that will work for many words? – user2922456 Sep 26 '14 at 14:44

1 Answers1

2

You are looking for expression similar to @"[\p{IsHebrew} ]+" - at least one character either Hebrew or space. To match whole sentence - add begin/end anchors - @"^[\p{IsHebrew} ]+$".

For detailed explanation see regular expression with hebrew or english and C#/.Net Character Classes in Regular Expressions.

Community
  • 1
  • 1
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
  • +1 for `\p{IsHebrew}`, I should remember to keep an eye on every question tagged [regex], there is always something new to learn... – Adriano Repetti Sep 26 '14 at 15:56