简体   繁体   中英

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. tested it on this tester

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

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

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

You have to backslash the "-", like this :

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

I think you should backslash all special char too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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