简体   繁体   English

JS中的正则表达式,不包含字母和相同的字符

[英]regex in JS for no letters and identical chars

got a problem with two regular expressions in javascript. 在javascript中遇到了两个正则表达式问题。 I need one expression that matches, when my string contains no a-zA-Z . 当我的字符串不包含a-zA-Z时,我需要一个匹配的表达式。 Like 12345 . 就像12345一样。 Stuff like \\W\\S or [^a-zA-Z] is not working, cause it matches 123a etc. Getting crazy with that one. \\W\\S[^a-zA-Z]的东西无法正常工作,原因是它匹配123a等。

The other expression is the matching of two identical letters like the 'ss' in password. 另一个表达式是两个相同字母的匹配,例如密码中的'ss' (.)\\1 is not working with javascript. (.)\\1无法使用javascript。 In c# no problem. 在C#中没有问题。 What am I doing wrong with that one? 我那是怎么了?

Made a section in my web.config which defines password-rules and in my code (c#, asp.net 3.5) I am reading the rules to create javascript for the client. 在我的web.config中定义了密码规则的部分以及我的代码(C#,asp.net 3.5)中,我正在阅读为客户端创建JavaScript的规则。

Thanks for help 感谢帮助

您还需要像这样使用开始和结束锚点,以确保您的完整字符串不与任何字母匹配:

/^[^a-zA-Z]+$/

以下正则表达式可以匹配连续的相同字符-

(\w)\1{1,}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM