且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

仅验证 A-Z、a-z、0-9、空格、句点、连字符 - 感叹号的正则表达式!问号?引号 "

更新时间:2022-11-14 21:21:23

大功告成.试试这个:

/^[a-zA-Z0-9 .!?"-]+$/

请注意,- 字符的位置很重要.如果它出现在两个字符之间(例如 a-z),则表示一个字符范围.如果它出现在字符类的开头或结尾(或者如果它被转义),它代表一个文字连字符.

Note that the position of the - character is important. If it appears between two characters (e.g. a-z) it represents a character range. If it appears in at the beginning or end of the character class (or if it's escaped) it represents a literal hyphen character.