简体   繁体   English

正则表达式,允许字母数字与空格并禁止某些特殊字符(<>&;)

[英]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.

相关问题 javascript-正则表达式字母数字和特殊字符 - javascript- regular expression alphanumeric and special characters 允许使用某些特殊字符,但必须使用字母数字 - Allow certain special characters, but alphanumeric is must JS 正则表达式 允许字母数字字符和。 , " ( ) - _ #: ; * @ &amp; 不剩余 +, =, $, ,, &lt;, &gt;, `, ~, {, }, |,\?,, ~ - JS regular expression Allow alphanumeric characters and . , " ( ) - _ # : ; * @ & not remaining +, =, $, !, <, >, `, ~, {, }, |,\,?, ~ 正则表达式允许数字或特殊字符 - Regular expression to allow either number or special characters 如何使用正则表达式在angularjs中允许字母数字和某些特殊字符 - How to allow alphanumeric and certain special characters in angularjs using regex 正则表达式,只允许字符或空格 - Regular expression which allow only characters or space 允许并阻止正则表达式中的某些字符? - Allow & prevent certain characters in a regular expression? JavaScript正则表达式(带_-的字母数字字符) - JavaScript regular expression ( alphanumeric characters with _-) 字母数字字符和-/仅的正则表达式 - Regular Expression for Alphanumeric characters and - / only Javascript正则表达式允许unicode,但不允许使用一些特殊字符,例如*,[,],〜等 - Javascript regular expression to allow unicode but disallow few special chars like *,[,],~ etc
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM