javascript - 正则表达式 jQuery 验证器包括非英文字符

标签 javascript jquery regex

好吧,我有一个网站 URL 验证器。它工作得很好,但我需要添加输入非英语字符的能力,如阿拉伯语等。我对正则表达式了解一点,但我不知道如何在这里允许阿拉伯字符,例如,而不是\w 或\a.

$('#WebSiteTextbox').blur(function () {

    patternurl = /([\d\w]+?:\/\/)?([\w\d\.\-]+)(\.\w+)(:\d{1,5})?(\/\S*)?/i
    if (!patternurl.test($("#WebSiteTextbox").val())) {
        $(this).attr('value','');
        $('.ValidatorError').html('Not Valid').slideDown().delay(5000).promise().done(function () {
            $(this).slideUp();
        });
    }
});

JSFiddle

最佳答案

您需要包含阿拉伯语和波斯语字符的特定字符范围。 \w可以表示为[A-Za-z0-9_]。您可以在同一 character class 中包含任何字符范围.

来自 Arabic script in Unicode :

  1. Arabic (0600—06FF, 255 characters)
    1. Arabic-Indic Digits (0660-0669)
    2. Extended Arabic-Indic Digits (06F0-06F9)
  2. Arabic Supplement (0750—077F, 48 characters)
  3. Arabic Extended-A (08A0—08FF, 50 characters)
  4. Arabic Presentation Forms-A (FB50—FDFF, 611 characters)
  5. Arabic Presentation Forms-B (FE70—FEFF, 140 characters)
  6. Rumi Numeral Symbols (10E60—10E7F, 31 characters)
  7. Arabic Mathematical Alphabetic Symbols (1EE00—1EEFF, 143 characters)

The basic Arabic range encodes the standard letters and diacritics, but does not encode contextual forms (U+0621–U+0652 being directly based on ISO 8859-6); and also includes the most common diacritics and Arabic-Indic digits. The Arabic Supplement range encodes letter variants mostly used for writing African (non-Arabic) languages. The Arabic Extended-A range encodes additional Qur'anic annotations and letter variants used for various non-Arabic languages. The Arabic Presentation Forms-A range encodes contextual forms and ligatures of letter variants needed for Persian, Urdu, Sindhi and Central Asian languages. The Arabic Presentation Forms-B range encodes spacing forms of Arabic diacritics, and more contextual letter forms. The presentation forms are present only for compatibility with older standards, and are not currently needed for coding text. The Arabic Mathematical Alphabetical Symbols block encodes characters used in Arabic mathematical expressions.

我认为你应该包括:

  • \w 中:13
  • \d 中:1.1

我相信这将包括英语、阿拉伯语和波斯语:

/(\w+:\/\/)?([-.a-z0-9_\u0600-\u06FF\u08A0-\u08FF]+)(\.\w+)(:\d{1,5})?(\/\S*)?/i
  • 我假设您不能在协议(protocol)、扩展名和端口号中使用阿拉伯字符,只能在域中使用。

关于javascript - 正则表达式 jQuery 验证器包括非英文字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33708043/

相关文章:

c# - 如何将哈希从 Live API for Contacts 的响应转换为文本

javascript - JS 闭包 - x 的值是多少?

javascript - 如何在 Javascript 中按特定顺序对数组进行排序

javascript - Thymeleaf/JavaScript 保留动态填充的选择元素的值

MySQL 正则表达式搜索查询

Python 的正则表达式模块 : repeating 'backreferences' does not appear to work correctly

javascript - 我如何等待多个 ajax 调用从 .each 循环完成

javascript - 下拉菜单项行为

javascript - 使用 ajax 和 jquery (php) 重定向页面

python - 在 python 中使用 [ 或 ( 的正则表达式