angular - Angular-reactive 表单输入字段的条件正则表达式
问题描述
正则表达式的图像我正在使用 Angular 反应形式并使用以下方法
password: [
'',
[
Validators.required,
Validators.pattern(this.passwordRegex),
],
paswordRegex = ^[a-zA-Z][a-zA-Z0-9]{8,20}$
在 HTML 中,我将 ngIF 条件用于 form['password'].invalid 并编写了密码要求标准。
但现在我需要制定条件类型的标准。假设用户通过了正则表达式的三个条件,它应该向通过的条件显示绿色,对失败的条件显示红色
<mat-error ........................ *ngIf="...">
<ul>
<li> must contain at least one digit</li><!-- condition passed= color=green-->
<li> can't start with a digit, underscore or special characters</li><!-- condition passed= color=green-->
<li> length must be between 8 to 20 alphanumeric characters</li><!-- condition fail= color=red-->
<li> only !@#$% special characters are allowed</li><!-- condition fail= color=red-->
</ul>
</mat-error>
只能从前端实现吗?
解决方案
推荐阅读
- jquery - 在不同的设备上调用 Jquery 命令
- symfony - 从数组中设置标签
- oracle-apex-5.1 - Oracle APEX - 将字段从集合转换为 DATE 类型
- r - 我如何在 prais winsten on r 中使用 rho
- api - BIM 360 和 Revit API
- java - 如何让 Byte Buddy 将多种类型加载到同一个包装类加载器中
- reactjs - 如何在页面上导航而不重新加载页面
- javascript - 我有两个独立的功能,一个收集表单文本,另一个切换图像的显示。我无法从其他变量中提取值
- apache-spark - 动态循环所有列名的数据集
- python - 通过在一段文本中查找关键字来过滤数据框