[英]Regular expression to allow alphanumeric with space and disallow certain special characters(<>&;)
I need helping in constructing a regular expression thats allows alphanumeric characters and disallows following special chararcters <>&; 我需要帮助构建一个允许使用字母数字字符的正则表达式,并且不允许遵循特殊的字符<>&; .
。 Please help.
请帮忙。
This regex matches alphanumeric and spaces: 此正则表达式匹配字母数字和空格:
var regex = /[a-z0-9\\s]*/i; var string = "All Alphanumeric"; console.log(string.match(regex));
If you want to allow certain symbols, just add those to the regex (eg the below regex also allows the email @
symbol and the .
: 如果要允许某些符号,只需将其添加到正则表达式中即可(例如,下面的正则表达式也允许使用电子邮件
@
符号和.
:
var regex = /[a-z0-9\\s@\\.]*/i; var string = "valid@email.domain"; console.log(string.match(regex));
The following regex matches everything except <>&;
以下正则表达式匹配除
<>&;
之外的所有内容<>&;
: :
const regex = /^[^<>&;]*$/ console.log(regex.test('Abc@123')) console.log(regex.test('Abc<123'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.