---
title: "Write Regex to verify the Person's Name with an explanation."  
description: "Write Regex to verify the Person's Name with an explanation."  
author: "Ravi Vishwakarma"  
published: 2024-12-10  
updated: 2024-12-17  
canonical: https://www.mindstick.com/forum/161051/write-regex-to-verify-the-person-s-name-with-an-explanation  
category: "programming language"  
tags: ["c#", ".net", "javascript", "java", "programming language"]  
reading_time: 2 minutes  

---

# Write Regex to verify the Person's Name with an explanation.

Write [Regex](https://www.mindstick.com/forum/160352/how-to-use-regex-in-javascript-for-pattern-matching) to verify the Person's [Name](https://yourviews.mindstick.com/view/87450/how-to-generate-a-brand-name-using-linkedin-comprehensive-guide) with an explanation.

## Replies

### Reply by Ravi Vishwakarma

```plaintext
^[A-Za-zÀ-ÿ\u0400-\u04FF\u0530-\u058F\u0370-\u03FF\u0590-\u05FF\u0600-\u06FF\u0900-\u097F\u4E00-\u9FFF]+(?:[\s'-][A-Za-zÀ-ÿ\u0400-\u04FF\u0530-\u058F\u0370-\u03FF\u0590-\u05FF\u0600-\u06FF\u0900-\u097F]+)*$
```

#### Explanation:

**1.** `^` **(Start of the string)**

- Ensures the regex matches from the start of the string.

**2.** `[A-Za-zÀ-ÿ\u0400-\u04FF\u0530-\u058F\u0370-\u03FF\u0590-\u05FF\u0600-\u06FF\u0900-\u097F\u4E00-\u9FFF]+`

- Matches **one or more** characters from:

   - `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]+)*`

- Non-capturing group `(?: ... )`:

   - Matches **zero or more** instances of:

      - `[\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.

> This allows for compound names with spaces, apostrophes, or hyphens (e.g., `Jean-Luc`, `O'Connor`, `Mary Jane`).

**4.** `$` **(End of the string)**

- Ensures the match goes to the end of the string.

## Key Features

- **It supports multiple languages,** Including Latin, Cyrillic, Greek, Hebrew, Arabic, Devanagari, and Chinese scripts.
- **Allows separators:** Supports names with spaces, hyphens, and apostrophes (e.g., `Mary-Jane`, `O'Neill`).
- **Ensures validity:** Names must start and end with a valid letter, disallowing extra spaces or invalid characters.

## Examples of Valid Names

1. `Jean-Luc` (Hyphenated name in Latin script)
2. `O'Connor` (Name with apostrophe)
3. `张伟` (Chinese characters)
4. `Алексей Иванов` (Cyrillic name with a space)
5. `محمد علي` (Arabic name with a space)
6. `राम श्याम` (Devanagari name with a space)

## Examples of Invalid Names

1. `John@Doe` (Contains an invalid character `@`)
2. `Jean--Luc` (Multiple consecutive hyphens)
3. `Zhang` (Leading space)
4. `John`(Trailing space)


---

Original Source: https://www.mindstick.com/forum/161051/write-regex-to-verify-the-person-s-name-with-an-explanation

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
