简体   繁体   English

如何通过angular2,验证仅在输入框中键入特定字符

[英]how to type only specific characters into inputbox by angular2, validations

I want to insert only specific characters such like '7' and '8' into inputbox. 我只想在输入框中插入诸如“ 7”和“ 8”之类的特定字符。 When I add validations and user input type="number" and min="7" max="8", i can insert other keys but during the next process I get validation messages. 当我添加验证和用户输入type =“ number”和min =“ 7” max =“ 8”时,我可以插入其他密钥,但是在下一个过程中,我会收到验证消息。 I could not find how to write specific characters before validation occurs. 在验证发生之前,我找不到如何写特定字符的方法。

Regards Alper 问候阿尔珀

My Snippet : 我的片段:

 <input type="number" min="0" max="12" name="input8">

try this 尝试这个

 <form [formGroup]="form" (ngSubmit)="submit()">
   <input type="number" min="0" max="12" name="input8" formControlName="input8" required>
   <span *ngIf="input8.touched && input8.errors">
    <span *ngIf="input8.errors.minlength">
    number at list 7 digit
    </span>
    <span *ngIf="input8.errors.maxlength">
    number is not greater than 8 digit
    </span>
    </span>
    </form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM