我试图逃避并在这个正则表达式的不同位置放置撇号,但我仍然得到错误。我需要把它放在哪里?
$.validator.addMethod("customvalidation",
function(value, element) {
return (/^[A-Za-z\d=#$%@_\-]+$/.test(value));
},
"Sorry, no special characters allowed"
);
我尝试过的事情:
//putting the apostraphe before the @ sign without escaping
(/^[A-Za-z\d=#$%'@_\-]+$/.test(value));
//putting the apostraphe as the last value in the brackets with and without escaping
(/^[A-Za-z\d=#$%'@_\- \']+$/.test(value));
答案 0 :(得分:1)
我已多次查看您的问题并完成了您的所有评论。这条评论罢工:
console.log(value) gives me the value of whatever is in the input such as:
Sade的帖子
你是对的,不成功:
/^[A-Za-z\d=#$%'@_-]+$/.test("Sade's Post");
问题不是apostrophe
,但输入字符串中存在空白未包含在您的角色类中
将您的角色类更改为包含空格:
[A-Za-z\d\s=#$%'@_-]
现在试试这个regex.test
:
result = /^[A-Za-z\d\s=#$%'@_-]+$/.test("Sade's Post");
// returns true now