[英]regex password validation angularjs
I am new to angular js. 我是棱角分明的新手。 I have created a login screen.
我创建了一个登录屏幕。 I need to validate my password.
我需要验证我的密码。 it should contain one special character from
-'$@£!%*#?&'
and at least one letter and number. 它应该包含一个特殊字符
-'$@£!%*#?&'
以及至少一个字母和数字。 As of now it accepts all special characters without any limitations. 截至目前,它接受所有特殊字符,没有任何限制。 I have following code
我有以下代码
if (vm.newpassword_details.password.search("^(?=.*?[A-Za-z])(?=.*?[0-9])(?=.*?[$@£!%*#?&]).{8,}$")) {
var msg = "Password should contain one special character from -'$@£!%*#?&' and at least one letter and number";
alert(msg);
}
Note that your current regex imposes 4 types of restriction: 请注意,您当前的正则表达式强加了 4种类型的限制:
(?=.*?[A-Za-z])
), (?=.*?[A-Za-z])
), (?=.*?[0-9])
), (?=.*?[0-9])
), (?=.*?[$@£!%*#?&])
) (?=.*?[$@£!%*#?&])
) .{8,}
) .{8,}
) The .
的
.
in .{8,}
can match any char other than line break chars. in
.{8,}
可以匹配除换行符之外的任何字符。
If you plan to restrict the .
如果你打算限制
.
and only allow users to type the chars from your sets, create a superset from them and use it with RegExp#test
: 并且只允许用户从你的集合中键入字符,从中创建一个超集并与
RegExp#test
一起使用:
if (!/^(?=.*?[A-Za-z])(?=.*?[0-9])(?=.*?[$@£!%*#?&])[A-Za-z0-9$@£!%*#?&]{8,}$/.test(vm.newpassword_details.password)) { /* Error ! */ }
See the regex demo 请参阅正则表达式演示
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.