English 中文(简体)
REGEX号密码,编号6个文件,至少一封信和一号,并可能包含特殊性质。
原标题:Password REGEX with min 6 chars, at least one letter and one number and may contain special characters

我需要有条件的定期表述:

  • min 6 characters, max 50 characters
  • must contain 1 letter
  • must contain 1 number
  • may contain special characters like !@#$%^&*()_+

目前,我有以下模式:(?!![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");
}

A more elegant and self-contained regex to match these (common) password requirements is:

^(?=.*[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.

为了接受所有符号,你只是说:“也接受所有非字母数字特性,而不是数字”。

Min and Max number of characters requirement

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)
}

International UTF-8

这里的任何解决办法都不允许国际信件,即: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.

首先,我们应当假设密码总是被打上(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,}$/;




相关问题
Anyone feel like passing it forward?

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. ...

How to Add script codes before the </body> tag ASP.NET

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 ...

Transaction handling with TransactionScope

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 ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

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!