20

So im using jquery validation on my script to only allows certain characters. I've had a request to allow the script to use arabic characters aswell. How would i do this?

Heres my current code:

    $.validator.addMethod(
    "legalname",
    function(value, element) {
        return this.optional(element) || /^[a-zA-Z0-9()._\-\s]+$/.test(value);
    },
    "Illegal character. Only points, spaces, underscores or dashes are allowed."
);
Josh Fradley
  • 545
  • 1
  • 10
  • 23
  • Search for "javascript unicode regex" - the middle word is important. (Unfortunately there are no explicit unicode character classes ..) –  Oct 11 '12 at 19:49

2 Answers2

33

Via this site you can easily create unicode regex for many languages:

Arabic:

[\u0600-\u06FF]
Mohsen Afshin
  • 13,273
  • 10
  • 65
  • 90
9

Try this:

function HasArabicCharacters(text)
{
    var arregex = /[\u0600-\u06FF]/;
    alert(arregex.test(text));
}

For more info take a look here Arabic Unicode block

Anton Baksheiev
  • 2,211
  • 2
  • 14
  • 15