Dedicated Regular Expression for Persian alphabet

You can use persianRex, it detects all Persian characters in different keyboard layouts and it's open source.

Download it and put it in your project folder. Then include it in your HTML like this:

<script src="persian-rex/dist/persian-rex.js"></script>

Then in your Javascript you can do this:

function Just_persian(str){
  if(persianRex.text.test(str))
    alert("not format");
}

Persian Characters are within the range: [\u0600-\u06FF] And: [\s]

Use This Code:

function Just_persian(str){
  var p=/@"^([\u0600-\u06FF]+\s?)+$"/;
  if(!str.match(p))
    alert("not format");
}

This Patern includes Letter and space Charachters.


Persian characters are within the Arabic Unicode block, which ranges from U+0600 to U+06FF (which is specified in character class as \u0600-\u06FF).

function just_persian(str){
    var p = /^[\u0600-\u06FF\s]+$/;

    if (!p.test(str)) {
        alert("not format");
    }
}

Adapted to JavaScript from this question: Regex for check the input string is just in persian language