我需要有条件的定期表述:
- min 6 characters, max 50 characters
- must contain 1 letter
- must contain 1 number
- may contain special characters like !@#$%^&*()_+
目前,我有以下模式:(?!![0-9]*$)?
然而,它没有允许特殊性,任何人是否对此有良好的规范?
增 编
我需要有条件的定期表述:
目前,我有以下模式:(?!![0-9]*$)?
然而,它没有允许特殊性,任何人是否对此有良好的规范?
增 编
也许可以使用单一管理标准,但很难向用户提供它们所依据的规则。 更传统的做法,使你们得到反馈意见,即你在《倡议》中可以用来告诉用户,哪些规则没有得到遵守:
function checkPwd(str) {
if (str.length < 6) {
return("too_short");
} else if (str.length > 50) {
return("too_long");
} else if (str.search(/d/) == -1) {
return("no_num");
} else if (str.search(/[a-zA-Z]/) == -1) {
return("no_letter");
} else if (str.search(/[^a-zA-Z0-9!@#$\%^&*()\_+]/) != -1) {
return("bad_char");
}
return("ok");
}
在 j子回答之后,我写了这一dle子,以测试他的解决方案,稍作改动,使之更能直观:
该法典是:
checkPwd = function() {
var str = document.getElementById( pass ).value;
if (str.length < 6) {
alert("too_short");
return("too_short");
} else if (str.length > 50) {
alert("too_long");
return("too_long");
} else if (str.search(/d/) == -1) {
alert("no_num");
return("no_num");
} else if (str.search(/[a-zA-Z]/) == -1) {
alert("no_letter");
return("no_letter");
} else if (str.search(/[^a-zA-Z0-9!@#$\%^&*()\_+.,;:]/) != -1) {
alert("bad_char");
return("bad_char");
}
alert("oukey!!");
return("ok");
}
b. 以前,它的工作像一个harm!
最好和感谢friend!
只包含特征、数字数字、强调和第一特性的7至16个特性之间的密码必须是字母。
^[A-Za-z]w{7,14}$/
核对6至20个性之间的密码,其中至少有一名数位数、一名高位数和一名下级字母。
^(?=d)(?=[a-z])(?=.*[A-Z]){6,20}$/
核对7至15个性之间的密码,其中至少包含一名数字和一种特殊性
^(?=[0-9])(?=[!@#%^&) [a-zA-Z0-9!@#$%^&]{7,15}$/
核对8至15个性之间的密码,其中至少载有1个下级信函、1个上层信函、1个数字数字和1个特性
^(?=d)(?=[a-z])(?=.[A-Z])(?=[^a-zA-Z0-9]?
^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d^a-zA-Z0-9].{5,50}$
The elegant touch here is that you don t have to hard-code symbols such as $ @ # etc.
为了接受所有符号,你只是说:“也接受所有非字母数字特性,而不是数字”。
The final part of the regex {5,50}
is the min and max number of characters, if the password is less than 6 or more than 50 characters entered the regex returns a non match.
我有一席之地,但只是一.。
^(?:(?<Numbers>[0-9]{1})|(?<Alpha>[a-zA-Z]{1})|(?<Special>[^a-zA-Z0-9]{1})){6,50}$
让我解释一下,以及如何检查经过测试的密码是否正确:
There are three named groups in the regex. 1) "Numbers": will match a single number in the string. 2) "Alpha": will match a single character from "a" to "z" or "A" to "Z" 3) "Special": will match a single character not being "Alpha" or "Numbers"
这三个名称的群体被归入另一个类别,{6,50}<>>>>>>
建议 regex用机器捕获至少6个上述群体,但不超过50个。
为确保进入正确的密码,你必须检查是否配对,然后,如果相应群体被捕获达到你所期望的程度。 I m a C# developer and una t knowledge, how it work in javascript, but in C#, Yousss toeck:
match.Groups["Numbers"].Captures.Count > 1
希望它能以 j语开展工作! 亲爱!
我使用了这一方法。
export const validatePassword = password => {
const re = /^(?=.*[A-Za-z])(?=.*d)[a-zA-Z0-9!@#$%^&*()~¥=_+}{":; ?/>.<,`-|[]]{6,50}$/
return re.test(password)
}
这里的任何解决办法都不允许国际信件,即:EöÖæÆóÓúÚáÁ,但主要侧重于english alphabet。
The following regEx use unicode, UTF-8, togni Superior and low case and, so, Admission international nature:
// Match uppercase, lowercase, digit or #$!%*?& and make sure the length is 6 to 50 in length
const pwdFilter = /^(?=.*p{Ll})(?=.*p{Lu})(?=.*[d|@#$!%*?&])[p{L}d@#$!%*?&]{6,50}$/gmu
if (!pwdFilter.test(pwd)) {
// Show error that password has to be adjusted to match criteria
}
This regEx
/^(?=*p{Ll})(?=*p{Lu})(?)=*[>[>#$%!*&] [p{L}d@#$!%*?&]{6,50}$/gmu
checks if an uppercase, lowercase, digit or #$!%*?& are used in the password. It also limits the length to be 6 minimum and maximum 50 (note that the length of ??????? emojis counts as more than one character in the length).
The u
in the end, tells it to use UTF-8.
DEMO https://jsfiddle.net/ssuryar/bjuhkt09/
关键职能触发。
<><><><>>><>>>>><>>>>>>
<form>
<input type="text" name="testpwd" id="testpwd" class="form=control" onkeyup="checksPassword(this.value)"/>
<input type="submit" value="Submit" /><br />
<span class="error_message spassword_error" style="display: none;">Enter minimum 8 chars with atleast 1 number, lower, upper & special(@#$%&!-_&) char.</span>
</form>
<><>>
function checksPassword(password){
var pattern = /^.*(?=.{8,20})(?=.*d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%&!-_]).*$/;
if(!pattern.test(password)) {
$(".spassword_error").show();
}else
{
$(".spassword_error").hide();
}
}
首先,我们应当假设密码总是被打上(right? 始终如一、正确?。 这意味着我们不应具体说明允许的准确特征(根据第4个子弹)。 相反,任何特性都应被接受,然后以最低长度和复杂程度加以验证(必须包含一封信和若干字,例如)。 由于这肯定会shed灭,我们对最长期限没有关切,应该能够消除这一要求。
我同意,这常常是作为单一管理机构,而是作为一系列小型管理机构来加以验证,因为我们可能希望向用户说明他们需要更新的东西,而不是仅仅拒绝将直言作为无效密码。 这里有一些选择:
如上文所述,有1份,1份(少有或少有)信,8份。 添加了第二种办法,使铅/游离空间解体(例如避免了带有额外白色空间的潜在问题)。
^(?=.*d)(?=.*[a-zA-Z]).{8,}$
^(?=.*d)(?=.*[a-zA-Z])S.{6,}S$
最后,如果你想要求1份数和1份上下级和1份下级信函,那么这种文字就能够奏效(有或不允许出现主导/干扰空间)。
^(?=.*d)(?=.*[a-z])(?=.*[A-Z]).{8,}$
^(?=.*d)(?=.*[a-z])(?=.*[A-Z])S.{6,}S$
最后,按照原员额(ain,don t do this,请尝试并重新提出要求!——1号、1封信(顶或下级)、1份特别果园(名单上)和8号,最高50个果园。 无论有无允许主要/外围空间,都注意到为说明所指明的2个非白色空间特性而做出的最小/最大变化。
^(?=.*d)(?=.*[a-zA-Z])(?=.*[!@#$%^&*()_+]).{8,50}$
^(?=.*d)(?=.*[a-zA-Z])(?=.*[!@#$%^&*()_+])S.{6,48}S$
Bonus - separated out is pretty simple, just test against each of the following and show the appropriate error in turn:
/^.{8,}$/ // at least 8 char; ( /^.{8,50}$/ if you must add a max)
/[A-Za-z]/ // one letter
/[A-Z]/ // (optional) - one uppercase letter
/[a-z]/ // (optional) - one lowercase letter
/d/ // one number
/^S+.*S+$/ // (optional) first and last character are non-whitespace)
请注意,在本规章中,写给一封信的果园是标准的英文26种,无任何强调性。 但我希望,这有足够的差异,因此民间人士可以按照需要加以调整。
// more secure regex password must be :
// more than 8 chars
// at least one number
// at least one special character
const PASSWORD_REGEX_3 = /^(?=.*d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*]).{8,}$/;
In my webpages I have references to js and images as such: "../../Content/Images/"Filename" In my code if I reference a file as above, it doesnt work so i have to write: "c:/miscfiles/"filename" 1-...
I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...
Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...
I m looking for best practices here. Sorry. I know it s subjective, but there are a lot of smart people here, so there ought to be some "very good" ways of doing this. I have a custom object called ...
I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...
i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...
For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?
I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!