views:

515

answers:

3

Is there a way to check if a string contains characters of a given language only? (for example Japanese, Hebrew, Arabic)

I'm wondering if there is a way implementing this kind of validation in Javascript\Jquery and in c#?

EDIT

I'm not willing to check if the string contains valid words of a specific language dictionary. I'd like to validate that all characters belong to that language.

A: 

Maybe using a regular expression with UNICODE charset?

eKek0
A: 

No, you cant check exact language. You can check only those chars which there no in other languages. For example cyriclics, hieroglyphs etc. Like a hint you can use google translate api to define in what lanuage user enters the text.

Eldar Djafarov
yes you can define arabic, just check in what regions of unicode arabic is.
Eldar Djafarov
I'm not willing to check if the string contains valid words of a specific language dictionary. I'd like to validate that all characters belong to that language.
CD
so First you really need to define a list of languages to support. And then check what regions of unicode table do they use.
Eldar Djafarov
+4  A: 

@CD, so sure you can do that.

In C#, just:

string str = "this text has arabic characters";
bool hasArabicCharacters = str.Any(c => c >= 0xFB50 && c <= 0xFEFC);
Cleiton
Thanks, Where did you find the values of Arabic characters?
CD
@Cd, i used the Character Map utility included in Windows :)
Cleiton
please note that u need to add [using System.Linq;] for the extention method to appear:)
Karim