如何为密码制作特定模式? [英] How can you make a specific pattern for a password?

查看:90
本文介绍了如何为密码制作特定模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的不明白模式是如何制作的,我读了一些关于RegEx的东西,它是否为不同的模式制作代码?



我没有得到的一个例子是:



国家代码:

I don't really understand how patterns are made, I read something about RegEx, does that make codes for different patterns?

An example I didn't get was this:

Country code:

<input type="text" name="country_code" 
pattern="[A-Za-z]{3}" title="Three letter country code">
<input type="submit">





我尝试过:



我只是没有得到模式部分,我没有得到这是三个字母国家代码的模式。



What I have tried:

I just didn't get the pattern part, I didn't get how that's the pattern for a three letter country code.

推荐答案

正则表达式可能变得相当复杂,但这很简单:

Regexes can get pretty complex, but that one's simple:
[A-Za-z]{3}
[      ]       The square brackets say "any character in this set"
 A-Z           "Any uppercase character"
            or
    a-z        "Any lowercase character"
        { }    The curly brackets say "Repeat the previous item a specific number of times"
         3     "Exactly three times"

所以整个正则表达式意味着任意三个大写或小写字母


如果您想体验正则表达式,请获取 Expresso 的副本[ ^ ] - 它'免费,它检查,解释和生成正则表达式。



Regeexs上还有一些非常好的全书:regexes book - Google搜索 [ ^ ]这将在一个小文本框中解释比我们更好的详细复杂性!



但是......正则表达式是一种工具,在这种情况下它们是模式匹配工具。它们必须在正确的位置使用,这是用于文本匹配操作 - 它们不是很好的atr字符串评估。所以,如果你想要一个像最少七个或更多字符这样的密码规则,那就没问题了:

So the whole regex means "any three upper or lower case letters"

If you want to experiment with Regexes, get a copy of Expresso[^] - it's free, and it examines, explains, and generates Regular expressions.

There are also some very good whole books on Regeexs: regexes book - Google Search[^] which will explain teh detailed complexities a lot better than we can in a little text box!

But ... Regexes are a tool, and in the case they are a pattern matching tool. They have to be used in the right place, and that is for text matching operations - they are not good atr string evaluation. So if you want a password rule like "seven or more characters minimum" that's fine:

.{7,}

任何角色,至少有七个。

但是如果你的规则是最少七个或更多字符,那么必须包括至少一个大写字母,一个数字和一个特殊字符然后一个正则表达式是错误的工具,因为它不能计算并处理这条线,所以正则表达式变得非常复杂并且无法维护。密码规则应该用实际代码编码,可能使用多个正则表来收集信息:一个用于多少个大写,一个用于多少个小写,另一个用于多少个数字,最后一个为多少特殊字符。然后代码使用这些数字来评估规则。

"Any character, at least seven of them".
But if your rule is "seven or more characters minimum, must include at least one upper case, one digit, and a special character" Then a regex is the wrong tool, because it's can't "count" and process the line, so teh regex becomes horribly complicated and impossible to maintain. Password rules should be coded in actual code, possibly using a number of regexes to gather the info: one for "how many upper case", one for "how many lower case", another for "how many digits", and a final one for "how many special characters". Those numbers then get used by the code to evaluate the rules.


这篇关于如何为密码制作特定模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆