简体   繁体   English

JavaScript正则表达式(带_-的字母数字字符)

[英]JavaScript regular expression ( alphanumeric characters with _-)

I am having trouble forming regular expression containing all alphanumeric characters and one or two specific characters, such us _ or - . 我无法形成包含所有字母数字字符和一个或两个特定字符的正则表达式,例如我们_-

This expression works for all alphanumeric characters /^[0-9a-zA-Z]+$/ . 此表达式适用于所有字母数字字符/^[0-9a-zA-Z]+$/

Add the special characters inside the square brackets 在方括号内添加特殊字符

/^[0-9a-zA-Z_-]+$/

To use this regex in javascript use this code ( yourPhrase is the string you check vs the regexp) 要在javascript中使用此正则表达式,请使用此代码( yourPhrase是您检查的字符串与正则表达式)

var rexp = /^[0-9a-zA-Z_-]+$/
if(rexp.test(yourPhrase)){
    //code to handle the test
}

Try this: 尝试这个:

/^[0-9a-zA-Z-_]+$/

If you enter the dash sign "-" at a position where it can be interpreted as a range such as _- it would mean any characters matching _ or above in the ascii table. 如果在可以将其解释为_-等范围的位置输入短划线符号“ - ”,则表示在ascii表中与_或以上匹配的任何字符。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 javascript-正则表达式字母数字和特殊字符 - javascript- regular expression alphanumeric and special characters 字母数字字符和-/仅的正则表达式 - Regular Expression for Alphanumeric characters and - / only JavaScript中字母数字正则表达式的问题 - Problem in alphanumeric regular expression in javascript JQuery正则表达式接受字母数字字符和&#39;, - - JQuery Regular expression to accept alphanumeric characters and ' , - JS 正则表达式 允许字母数字字符和。 , " ( ) - _ #: ; * @ &amp; 不剩余 +, =, $, ,, &lt;, &gt;, `, ~, {, }, |,\?,, ~ - JS regular expression Allow alphanumeric characters and . , " ( ) - _ # : ; * @ & not remaining +, =, $, !, <, >, `, ~, {, }, |,\,?, ~ 正则表达式字母数字字符-允许连字符和下划线 - regular expression alphanumeric characters - allowing hyphens and underscores [字母数字] [字母数字.__ @] 31个字符的正则表达式建议 - Regular Expression advice for [Alphanumeric][alphanumeric.-_@] 31 characters Javascript正则表达式:匹配所有字母数字字符,除所有空白外,允许使用破折号和下划线 - Javascript regular expression: Match all alphanumeric characters, allow dashes spaces and underscores except all whitespace 在JavaScript中,如何更改正则表达式以匹配所有非字母数字字符? - In JavaScript, how do I change my regular expression to match all non-alphanumeric characters? 正则表达式,允许字母数字与空格并禁止某些特殊字符(&lt;&gt;&;) - Regular expression to allow alphanumeric with space and disallow certain special characters(<>&;)
相关标签
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM