Home >Backend Development >PHP Tutorial >javascript - Can anyone please help me write a regular expression that requires numbers, letters, underlines, and underscores to prohibit the occurrence of @?

javascript - Can anyone please help me write a regular expression that requires numbers, letters, underlines, and underscores to prohibit the occurrence of @?

WBOY
WBOYOriginal
2016-12-01 01:27:481259browse

<code class="javascript">
var reg = /^[\w]{6,12}$/ ;  

if(password.match(reg)){
    alert("The password is valid!");
} 
</code>

现在要求 长度为6-16 位字符,可以为“数字/字母/中划线/下划线” ,不能为全下划线和全中划线和全数字

回复内容:

<code class="javascript">
var reg = /^[\w]{6,12}$/ ;  

if(password.match(reg)){
    alert("The password is valid!");
} 
</code>

现在要求 长度为6-16 位字符,可以为“数字/字母/中划线/下划线” ,不能为全下划线和全中划线和全数字

<code>let reg = /^(?!^-+$)(?!^_+$)(?!^\d+$)[\d|a-zA-Z|\-|_]{6,16}$/;

let test = ['1234567', '-------', '_______', 'cdwcdcd23@'];
test.map(str => console.log(reg.test(str)));</code>

/^(w|_|-)+$/.test("abcA5557_78-")

一个正则做不到吧,分开写吧。/^[w-]{6-12}$//^d{12}$/ ...

/^(?!(-|_)\1{5,15}$)(?!\d{6,16}$)[-\w]{6,16}$/

<code>var reg = /^(?!(-|_)\1{5,15}$)(?!\d{6,16}$)[-\w]{6,16}$/;
undefined
reg.test('1234567'); //全数字
false
reg.test('_______');//全下划线
false
reg.test('-------');//全中划线
false
reg.test('____---');
true
reg.test('abcddd');
true
reg.test('__12__---aa');
true</code>

正则不是很会 尴尬

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn