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

WBOY
Release: 2023-03-02 13:26:02
Original
1199 people have browsed it

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

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

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

回复内容:

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

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

现在要求 长度为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>
Copy after login

/^(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>
Copy after login

正则不是很会 尴尬

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!