gpt4 book ai didi

angular6 - Angular 6 - 模糊的表单验证

转载 作者:行者123 更新时间:2023-12-04 16:29:47 25 4
gpt4 key购买 nike

我想验证在 onBlur 中填写的输入,我该怎么做。请帮帮我。

<form class="form-horizontal" role="form" name="form" id="form"
(ngSubmit)="f.form.valid && onSubmit()"
#f="ngForm" novalidate>

<input type="text" class="form-control" placeholder="Social Id"
[ngModel]="generalUserData.socialId" [maxlength]=12 name="socialId" [minlength]=10
(blur)="onBlurMethod($event.target.name, $event.target.value ,generalUserData)"
#socialId="ngModel" [ngClass]="{ 'is-invalid': f.submitted && socialId.invalid }"
pattern="\d{9}(v|V)|\d{12}" required/>
<div *ngIf="f.submitted && socialId.invalid" class="invalid-feedback">
<div *ngIf="socialId?.errors.required">NIC is required</div>
<div *ngIf="socialId?.errors.minlength">NIC must be at least 10 characters long.</div>
<div *ngIf="socialId?.errors.pattern">Not valid NIC</div>
<div *ngIf="socialId?.errors.maxlength">NIC must be less than 12 characters long.</div>
</div>
</form>

我使用了下面的示例 link然后我想验证模糊我该怎么做。

最佳答案

onBlur() 方法自 Angular 5 起已更改。对于模板驱动的表单,您需要使用以下语法:

<input [(ngModel)]="lastname" [ngModelOptions]="{ updateOn: 'blur' }">

这里是demo,希望对你有帮助:

https://codingthesmartway.com/angular5-forms-update/

关于angular6 - Angular 6 - 模糊的表单验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51704616/

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