gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 16:28:40 24 4
gpt4 key购买 nike

好吧,我有一个网站 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com