尝试在 javascript 的用户输入中检查 < 或 >。 知道正则表达式是什么吗? 这个正则表达式似乎不起作用
var spclChar=/^[<>]$/;
if(searchCriteria.firstName.match(spclChar)){
return true;
}else {
return false;
}
最佳答案
您可以使用这样的字符类:
[<>]
or
[><]
顺便说一句,您的问题中有有用的评论,例如 Sam 的
/[<>]/
和 Marc B 的
your regex is searching for a < at the START of the string, or a > at the END of the string. if you want them ANYWHERE in the string, then dump the ^ and $. – Marc B 7 mins ago
关于javascript - 如何检查 javascript 输入中的特殊字符 "<"或 ">"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32190052/