javascript中反斜杠的RegExr超出范围
我使用\(bakcslash)进行regExr匹配时出现超出范围的错误。。解决方案请javascript中反斜杠的RegExr超出范围,javascript,regex,Javascript,Regex,我使用\(bakcslash)进行regExr匹配时出现超出范围的错误。。解决方案请 if ($('.channelquickvalidte').val().match("^[a-zA-Z\s0-9, '@+&$,._!#%^*()_+=/<>\\]+$") == null) /* Error... */ { alert("Character between A-Z/a-z and 0-9 are allowed. Additional you can use \"''
if ($('.channelquickvalidte').val().match("^[a-zA-Z\s0-9, '@+&$,._!#%^*()_+=/<>\\]+$") == null) /* Error... */
{ alert("Character between A-Z/a-z and 0-9 are allowed. Additional you can use \"''@+&,._$!#%^*()_+=<>/\\\" character"); // its working fine
不要将反斜杠放在char类的末尾,请使用:
match("^[a-zA-Z\s0-9, '@+&$,._!#%^*()_+=/\\<>]+$")
match(“^[a-zA-Z\s0-9,@+&$,.\\\\%^*()。+=/\\]+$”)
或
match(“^[a-zA-Z\s0-9,@+&$,.\\\\%^*()。+=/\\\]+$”)
您可以将其简化为:
match("^[\w\s,'@+&$,.!#%^*()+=/\\<>]+$")
match(“^[\w\s,@+&$,.!\%^*()+=/\\]+$”)
\w
通常代表[a-zA-Z0-9\
,但它取决于语言环境。\s
代表任何空格字符,即[\t\r\n\f]
,因此您不需要在car类中增加空格如果您的character类中也有“`”,为什么还要在字符类中添加\s
?尝试删除\s
或将其移动到其他位置。我可以想象,js以某种奇怪的方式解释\s0
,从而产生错误。
match("^[a-zA-Z\s0-9, '@+&$,._!#%^*()_+=/<>\\\\]+$")
match("^[\w\s,'@+&$,.!#%^*()+=/\\<>]+$")