gpt4 book ai didi

javascript - 如何在某些条件下使用 Angular 8 中的正则表达式添加密码验证?

转载 作者:行者123 更新时间:2023-11-27 23:04:22 25 4
gpt4 key购买 nike

我想根据以下条件验证用户输入的密码:

密码最少8个字符,最多20个字符,其中只能包含一个数字、一个大写字符和一个特殊字符,./<>?;':"[]{}\|!@#$%^&*(-=_+ (.

为此我使用了以下正则表达式:

Password: ['', [Validators.pattern('(?=.[a-z])(?=.[A-Z])(?=.[0-9])(?=. [$@$!%#?^&+=,.-])[A-Za-z\d$@$!%#?^&+=,.- ].{8,}')]]``

最佳答案

您可以通过以下两个步骤添加您的图案:

  • 在 HTML 文件中

    <div *ngIf="f.Password.errors.required">
    This field is mandatory</div>
    <div *ngIf="f.Password.errors.minlength">
    Must be at least 8 digits</div>
    <div *ngIf="f.Password.errors.maxlength">
    Must be Max 20 digits</div>
    <div *ngIf="f.Password.errors.pattern">
    Must contain at least 1 Special Character!</div>
  • 在ts文件中

    密码:[空, [ Validators.required, Validators.minLength(8), Validators.maxLength(20), Validators.pattern(/[ !@#$%^&*()_+-=[]{};':"\|,.<>/?][a-zA-Z0-9 ]/) ]]

运行演示 - https://stackblitz.com/edit/angular-shhd1i

关于javascript - 如何在某些条件下使用 Angular 8 中的正则表达式添加密码验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58813850/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com