I have a question: I want to do a validation for the first and the last name with RegEx. I want to do it with only Hebrew and English without numbers. Someone can help me to do that code?
Seemingly Hebrew has the range \u0590-\u05fe
(according to this nice JavaScript Unicode Regex generator`.
/^[a-z\u0590-\u05fe]+$/i
$
in there as well for the end of the string? –
Dairying \u200f
\u200e
). It could be a problem if the user changes from Hebrew to English and vice versa. My solution covers it https://mcmap.net/q/555381/-regex-to-match-hebrew-and-english-characters-except-numbers –
Carryingon \p{IsHebrew}
instead of \u0590-\u05fe
(see learn.microsoft.com/en-US/dotnet/standard/base-types/…) –
Procurance While the selected answer is correct about "Hebrew" the OP wanted to limit validation to only Hebrew and English letters. The Hebrew Unicode adds a lot of punctuation and symbols (as you can see in the table here) irrelevant for such validation. If you want only Hebrew letters (along with English letters) the regex would be:
/^[a-z\u05D0-\u05EA]+$/i
I would consider adding ' (single quote) as well, for foreign consonants that are missing in Hebrew (such as G in George and Ch in Charlie) make use of it along with a letter:
/^[a-z\u05D0-\u05EA']+$/i
English & Hebrew FULL regex
I'm using the above regex on my application. My users are just fine with it:
RegExp(r'^[a-zA-Z\u0590-\u05FF\u200f\u200e ]+$');
The regex supports:
- English letters (includes Capital letters).
a-zA-Z
- Hebrew (includes special end-letters).
\u0590-\u05FF
- change direction unicodes (RLM, LRM).
\u200f\u200e
- White space.
Enjoy!
Try this. Not sure if it will work. If not, these references should help.
[A-Za-z\u0590-\u05FF]*
^
) or end($
) of the string. –
Dairying You can also use \p{Hebrew}
in your regex to detect any Hebrew unicode characters (if you're regex engine supports it).
Well, the RegEx pattern is between two /
's. The i
at the end is a flag that says to be indifferent to the cases. ^
means the start of a line, and $
means the end of a line. Brackets ([
and ]
) means either of the characters inside the brackets. -
means a range. Note that the characters are ordinal, so a-z
or א-ת
make sense; a-z
means all letters from and include a
to and include z
. The same goes for א-ת
. +
means one or more of the preceding. So this pattern matches every sequence of letters from English or Hebrew.
P.S.: Also, note that the flavor of the RegEx is different in different languages and platforms. for example in Sublime Text
the pattern would be: (?i)^[א-תa-z]+$
.
/^[א-תa-z]+$/i
Swift 5 This work for me: Hebrew, English
NSRegularExpression(pattern: "^[\\p{Hebrew} a-z]$", options: .caseInsensitive).firstMatch(in: value, options: [], range: NSRange(location: 0, length: value.count))
Another languages you can get here - https://h2s1880.medium.com/how-to-use-regular-expressions-to-distinguish-national-languages-in-swift-c19d6d8d0a97
© 2022 - 2024 — McMap. All rights reserved.