Arwa
Arwa

Reputation: 3

What is the validation expression to allow english and arabic and spaces in a textbox

I need to validate English / Arabic letters only with spaces in a textbox. I used below validation expressions, it accepts English / Arabic text, But it did not accept any spaces. Can anyone give me the right expression.

^[\u0600-\u065F\u066A-\u06EF\u06FA-\u06FFa-zA-Z]+[\u0600-\u065F\u066A-\u06EF\u06FA-\u06FFa-zA-Z-_]*$

Upvotes: 0

Views: 276

Answers (2)

Javed Kalaniya
Javed Kalaniya

Reputation: 21

Here is the working solution for the regular expression pattern. It will accept all possible formats of Arabic alphabets without any special characters or numbers except space.

@"^[A-Za-z\u0621-\u065B\u066E-\u06D3\u06D5-\u06DC\u06E1-\u06E8\u06ED-\u06EF\u06FA-\u06FF ]+$"

I tested this in one of my applications which accepts both Arabic and English names with spaces.

Here is the full method of validation that you can use (Code is in C#)

public static bool IsValidAlphabetsOnly(string text)
{
     if (string.IsNullOrEmpty(text))
          return false;

     return Regex.IsMatch(text, @"^[A-Za-z\u0621-\u065B\u066E-\u06D3\u06D5-\u06DC\u06E1-\u06E8\u06ED-\u06EF\u06FA-\u06FF ]+$");
}

Upvotes: 0

3li
3li

Reputation: 618

It is called a Regular Expression. To allow whitespaces, you need to add a whitespace to the set.

^[\u0600-\u065F\u066A-\u06EF\u06FA-\u06FFa-zA-Z-_ ]+$

This Regular Expression accepts English, Arabic letters and whitespaces. It also accetps only whitespace with no letters.

Upvotes: 0

Related Questions