本文介绍了ng-pattern,用于密码文本,以接受所有特殊字符和数字,字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HTML
<form novalidate class="css-form">
username <input type="text"
ng-pattern="/^(?=.*[A-Za-z])(?=.*\d)(?=.*[$@('@')$!%*#?&])[A-Za-z\d$@('@')$!%*#?&]{8,20}$/" ng-model="user.email" required /><br />
</form>
上面的模式对于下面的符号运行正常
Above pattern is working fine for below symbols
@ # $ % & ! *
但是我想允许所有特殊字符,例如
But I want to allow all special characters like
{ } [ ] < > ( ) ^ + - = ; : ' " / \ |
如何在该模式中包含所有应该用于密码的特殊字符?
How to include all special characters in that pattern that should work for password?
推荐答案
使用以下ng-pattern
:
ng-pattern="/^(?=.*[A-Za-z])(?=.*\d)(?=.*[$@('@')$!%*#?&{}[\]<>()^+=;:'"/\\|-])[A-Za-z\d$@('@')$!%*#?&{}[\]<>()^+=;:'"/\\|-]{8,20}$/"
请注意,字符类中的\
和]
用\
进行了转义,并且双引号表示为"
HTML实体.在字符类结尾时,连字符不需要转义 .
Note that \
and ]
are escaped in the character class with \
and the double quotes are represented as a "
HTML entity. The hyphen does not need escaping when at the character class end.
请参见已更新的plunkr .
这篇关于ng-pattern,用于密码文本,以接受所有特殊字符和数字,字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!