简体   繁体   English

将“APP”作为前缀,然后只允许输入字段中的数字

[英]Have "APP" as prefix and then allow only numbers in input field

I have a requirement where I have an input field, that must have the prefix "APP " and then allow the user to type in 7 numeric only values.我有一个输入字段的要求,该字段必须具有前缀“APP”,然后允许用户输入 7 个纯数字值。 I was hoping I could use ngx-mask, but it doesn't seem possible.我希望我可以使用 ngx-mask,但似乎不可能。 Alternatively I was thinking of using (focusin) event like:或者,我正在考虑使用(focusin)事件,例如:

(focusin)="addPrefix($event)"

inputValue = "";
addPrefix(ev: any){
 inputValue = "APP ";
}

and then having a keyup event which would disregard key presses if input.length <= 3.But then comes this issue of pasting values in. Does anyone else have any better ideas/suggestions?然后有一个 keyup 事件,如果 input.length <= 3 则忽略按键。但是接下来是粘贴值的问题。还有其他人有更好的想法/建议吗? Thanks谢谢

Stackblitz 堆栈闪电战

How about,怎么样,

<input type="text" prefix="APP " mask="0000000" [clearIfNotMatch]="true" />

using ngx-mask?使用 ngx 掩码?

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

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