我尝试为仅接受字母,数字,短划线和下划线的特定字段添加规则,但破折号未包含在规则中。问题是,如何使用以下格式将破折号添加到字符中。
jQuery.validator.addMethod("custom-rule", function(value, element) {
return this.optional(element) || /^\w+$/i.test(value);
}, "Letters, numbers, dashes and underscores only please");
答案 0 :(得分:1)
使用character class在正则表达式中添加短划线和单词字符。
const xhr = new XMLHttpRequest();
xhr.onload = function () {
// TODO: get HTTP response text
};
xhr.open('GET', '/');
xhr.send();