How to check if any Arabic character exists in the string ( javascript )

后端 未结 5 1705
南方客
南方客 2020-12-05 01:03

How to check if any Arabic character exists in the string with javascript language

相关标签:
5条回答
  • 2020-12-05 01:17

    According to Wikipedia, Arabic characters fall in the Unicode range 0600 - 06FF. So you can use a regular expression to test if the string contains any character in this range:

    var arabic = /[\u0600-\u06FF]/;
    var string = 'عربية‎'; // some Arabic string from Wikipedia
    
    alert(arabic.test(string)); // displays true
    
    0 讨论(0)
  • 2020-12-05 01:17
    function isArabic(text) {
        var pattern = /[\u0600-\u06FF\u0750-\u077F]/;
        result = pattern.test(text);
        return result;
    }
    
    0 讨论(0)
  • 2020-12-05 01:26

    use this

    containsArabicNumber(text){
        var reg = /[۰١٢٣٤٥٦٧٨٩]/;
        return reg.test(text);
    }
    
    0 讨论(0)
  • 2020-12-05 01:27

    Ranges for Arabic characters are:

    0x600  - 0x6ff
    
    0x750  - 0x77f
    
    0xfb50 - 0xfc3f
    
    0xfe70 - 0xfefc
    
    0 讨论(0)
  • 2020-12-05 01:28

    how it work for me is

    $str = "عربية";
    if(preg_match("/^\x{0600}-\x{06FF}]+/u", $str))echo "invalid";
    else echo "valid";
    

    You can check extended range of Arabic character

    0x600  - 0x6ff
    0x750  - 0x77f
    0xfb50 - 0xfc3f
    0xfe70 - 0xfefc
    

    So expression will look more like "/^\x{0600}-\x{06FF}\x{0750}-\x{077f}]+/u"
    Good Luck

    0 讨论(0)
提交回复
热议问题