0

The company I work in decided to sell a product to an Arab company.

I need a way to be sure that a string is just arabic letters or numbers (with space ofc).

how to do that please?

I searched on google but it seems that the arabic language is not so popular

Dmitry
  • 13,797
  • 6
  • 32
  • 48
Agnieszka Polec
  • 1,471
  • 6
  • 20
  • 26

2 Answers2

3

I think you can use this regexp expression for what you need:

[\u0600-\u06ff]\?[ ]\?[0-9]\?

The [\u0600-\u06ff] is for the arabic characters.

Example:

internal bool HasArabicCharacters(string text)
{

  Regex regex = new Regex(

    "[\u0600-\u06ff]\?[ ]\?[0-9]\?");

  return regex.IsMatch(text);
}
Estevex
  • 791
  • 8
  • 17
1

The best way to do this in my opinion is by Regular Expression.

Regex is a very powerful tool for these kind of tasks.

for example, you can write the following expression to filter only Arabic letters (I've used that for Hebrew): \p{IsArabic}

There is a built-in support for Character Classes in Regex.

Please find attached a great link that helped me understand exactly what is possible and how: http://msdn.microsoft.com/en-us/library/20bw873z(v=vs.110).aspx

In addition, a must have tool for any Regex developer that both helps you create expressions visually, and evaluate those expressions against data and review the results. Expresso: http://www.ultrapico.com/ExpressoDownload.htm

Hope this helps, Ofir.

Ofir Makmal
  • 501
  • 2
  • 3