admin管理员组文章数量:1026989
The language is javascript.
Strings that would pass:
JavaScript1*
Pu54 325
()9c
Strings that would not pass:
654fff
%^(dFE
I tried the following:
var matches = password.match(/\d+/g);
if(matches != null)
{
//password contains a number
//check to see if string contains a letter
if(password.match(/[a-z]/i))
{
//string contains a letter and a number
}
}
The language is javascript.
Strings that would pass:
JavaScript1*
Pu54 325
()9c
Strings that would not pass:
654fff
%^(dFE
I tried the following:
var matches = password.match(/\d+/g);
if(matches != null)
{
//password contains a number
//check to see if string contains a letter
if(password.match(/[a-z]/i))
{
//string contains a letter and a number
}
}
Share
Improve this question
edited Nov 30, 2016 at 7:05
Michael Drum
asked Nov 30, 2016 at 6:47
Michael DrumMichael Drum
1,2395 gold badges15 silver badges28 bronze badges
1
- Yes. I tried many things. – Michael Drum Commented Nov 30, 2016 at 7:00
1 Answer
Reset to default 5You can use Regex:
I took it from here: Regex for Password
var checkPassword = function(password){
return !!password.match(/^(?=.*[A-Za-z])(?=.*\d)(?=.*[$@$!%* #+=\(\)\^?&])[A-Za-z\d$@$!%* #+=\(\)\^?&]{3,}$/);
};
I use this Regex:
Minimum 3 characters at least 1 Alphabet, 1 Number and 1 Special Character:
"^(?=.*[A-Za-z])(?=.*\d)(?=.*[$@$!%* #=+\(\)\^?&])[A-Za-z\d$@$!%* #=+\(\)\^?&]{3,}$"
This regex will enforce these rules:
At least one English letter, (?=.*?[A-Za-z])
At least one digit, (?=.*\d)
At least one special character, (?=.[$@$!% #+=()\^?&]) Add more if you like...
Minimum length of 3 characters (?=.[$@$!% #?&])[A-Za-z\d$@$!%* #+=()\^?&]{3,} include spaces
If you want to add more special characters, you can add it to the Regex like I have added '(' (you need to add it in two places).
And for those of you who ask yourself what are those two exclamation points, here is the answer: What is the !! (not not) operator in JavaScript?
The language is javascript.
Strings that would pass:
JavaScript1*
Pu54 325
()9c
Strings that would not pass:
654fff
%^(dFE
I tried the following:
var matches = password.match(/\d+/g);
if(matches != null)
{
//password contains a number
//check to see if string contains a letter
if(password.match(/[a-z]/i))
{
//string contains a letter and a number
}
}
The language is javascript.
Strings that would pass:
JavaScript1*
Pu54 325
()9c
Strings that would not pass:
654fff
%^(dFE
I tried the following:
var matches = password.match(/\d+/g);
if(matches != null)
{
//password contains a number
//check to see if string contains a letter
if(password.match(/[a-z]/i))
{
//string contains a letter and a number
}
}
Share
Improve this question
edited Nov 30, 2016 at 7:05
Michael Drum
asked Nov 30, 2016 at 6:47
Michael DrumMichael Drum
1,2395 gold badges15 silver badges28 bronze badges
1
- Yes. I tried many things. – Michael Drum Commented Nov 30, 2016 at 7:00
1 Answer
Reset to default 5You can use Regex:
I took it from here: Regex for Password
var checkPassword = function(password){
return !!password.match(/^(?=.*[A-Za-z])(?=.*\d)(?=.*[$@$!%* #+=\(\)\^?&])[A-Za-z\d$@$!%* #+=\(\)\^?&]{3,}$/);
};
I use this Regex:
Minimum 3 characters at least 1 Alphabet, 1 Number and 1 Special Character:
"^(?=.*[A-Za-z])(?=.*\d)(?=.*[$@$!%* #=+\(\)\^?&])[A-Za-z\d$@$!%* #=+\(\)\^?&]{3,}$"
This regex will enforce these rules:
At least one English letter, (?=.*?[A-Za-z])
At least one digit, (?=.*\d)
At least one special character, (?=.[$@$!% #+=()\^?&]) Add more if you like...
Minimum length of 3 characters (?=.[$@$!% #?&])[A-Za-z\d$@$!%* #+=()\^?&]{3,} include spaces
If you want to add more special characters, you can add it to the Regex like I have added '(' (you need to add it in two places).
And for those of you who ask yourself what are those two exclamation points, here is the answer: What is the !! (not not) operator in JavaScript?
本文标签:
版权声明:本文标题:javascript - How do I check if a string contains at least one number, letter, and character that is neither a number or letter? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1742162958a1915697.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论