Write Regex to verify the Person's Name with an explanation.
Write Regex to verify the Person's Name with an explanation.
9910-Dec-2024
Updated on 17-Dec-2024
Home / DeveloperSection / Forums / Write Regex to verify the Person's Name with an explanation.
Write Regex to verify the Person's Name with an explanation.
Ravi Vishwakarma
17-Dec-2024Explanation:
1.
^
(Start of the string)2.
[A-Za-zÀ-ÿ\u0400-\u04FF\u0530-\u058F\u0370-\u03FF\u0590-\u05FF\u0600-\u06FF\u0900-\u097F\u4E00-\u9FFF]+
A-Za-z
: Latin alphabets (both uppercase and lowercase).À-ÿ
: Latin-based alphabets with diacritics (e.g.,é
,ñ
, etc.).\u0400-\u04FF
: Cyrillic characters.\u0530-\u058F
: Armenian characters.\u0370-\u03FF
: Greek characters.\u0590-\u05FF
: Hebrew characters.\u0600-\u06FF
: Arabic characters.\u0900-\u097F
: Devanagari characters (used in Hindi and other Indian languages).\u4E00-\u9FFF
: Chinese characters.This section ensures the name can start with letters from supported languages.
3.
(?:[\s'-][A-Za-zÀ-ÿ\u0400-\u04FF\u0530-\u058F\u0370-\u03FF\u0590-\u05FF\u0600-\u06FF\u0900-\u097F\u4E00-\u9FFF]+)*
(?: ... )
:[\s'-]
: A space (\s
), apostrophe ('
), or hyphen (-
).[A-Za-zÀ-ÿ\u0400-\u04FF\u0530-\u058F\u0370-\u03FF\u0590-\u05FF\u0600-\u06FF\u0900-\u097F\u4E00-\u9FFF]+
: One or more valid letters from the supported languages.4.
$
(End of the string)Key Features
Mary-Jane
,O'Neill
).Examples of Valid Names
Jean-Luc
(Hyphenated name in Latin script)O'Connor
(Name with apostrophe)张伟
(Chinese characters)Алексей Иванов
(Cyrillic name with a space)محمد علي
(Arabic name with a space)राम श्याम
(Devanagari name with a space)Examples of Invalid Names
John@Doe
(Contains an invalid character@
)Jean--Luc
(Multiple consecutive hyphens)Zhang
(Leading space)John
(Trailing space)