仅验证 A-Z、a-z、0-9、空格、句点、连字符 - 感叹号的正则表达式!问号?引号 " [英] Regular Expression to validate only A-Z, a-z, 0-9, space, period, hyphen - exclamation mark ! question mark ? quotes "

查看:54
本文介绍了仅验证 A-Z、a-z、0-9、空格、句点、连字符 - 感叹号的正则表达式!问号?引号 "的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用正则表达式来验证用户输入的文本.

I want to use regular expression which validate the text which user enter.

/^[a-zA-Z0-9 ]+$/

通过上面的行,我们只能允许字母、数字和空格.

By above line, we can allow only Alphabetic, Numbers and Space.

什么是正则表达式允许:

What will be regular expression to allow:

字母,
数字,
空间,
期间.
连字符 -
感叹号!
问号?
引号

alphabetic,
numbers,
space,
period .
hyphen -
exclamation mark !
question mark ?
quotes "

除了以上字符用户不能输入其他字符.

Except above characters user can not enter other characters.

谢谢,小白兔

推荐答案

大功告成.试试这个:

/^[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.

这篇关于仅验证 A-Z、a-z、0-9、空格、句点、连字符 - 感叹号的正则表达式!问号?引号 "的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆