简体   繁体   English

为什么此pregmatch模式在数字输入上返回true?

[英]Why does this pregmatch pattern return true on a number input?

I know this is very basic for some, but this got my head scratching. 我知道这对某些人来说是非常基本的,但这使我抓狂。 why does this pattern 为什么这种模式

/[!@#$%^&*()+|.*-<>\'`]/ 

return true on a number input ie abcd123. 在数字输入(即abcd123)上返回true。 tested it on this tester 这个测试仪上测试了它

您需要转义破折号,否则将其解释为字符范围\\x2A-\\x3E

/[!@#$%^&*()+|.*\-<>\'`]/ 

这是因为-在您的正则表达式中签名。

You have to backslash the "-", like this : 您必须反斜杠“-”,如下所示:

/[!@#$%^&()+|.\-<>\'`]/

I think you should backslash all special char too. 我认为您也应该反斜杠所有特殊字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM