1

I want to validate the text of customer input using jQuery. If the customer enter Arabic text I would like to show message in Arabic. How can I do that?

user2864740
  • 60,010
  • 15
  • 145
  • 220
Mani
  • 21
  • 2
  • 1
    http://stackoverflow.com/questions/1192768/how-to-detect-the-language-of-a-string/1192802#1192802 – Pranav C Balan Aug 30 '14 at 07:49
  • If these are the only two languages of concern, one could simply check for [Arabic Unicode code-points](http://en.wikipedia.org/wiki/Arabic_script_in_Unicode) as it is unlikely that any will be entered by an English customer. It is much harder problem to classify different languages sharing mostly the same character-set (such as English and German). – user2864740 Aug 30 '14 at 07:50

1 Answers1

10

Try this:

isArabic('Some Text');

function isArabic(strInput)
{
    var arregex = /[\u0600-\u06FF]/;
    if (arregex.test(strInput)){
        alert('Yes, Has Arabic Characters');
    }else{
        alert('No, Has Not Arabic Characters');
    }
}

Check JSFiddle Demo

Moshtaf
  • 4,833
  • 2
  • 24
  • 34