我有2个输入值,我需要对第一个from openpyxl import load_workbook
wb = load_workbook('company_info.xlsx')
ws = wb['Sheet1']
for i in range(1, ws.max_row + 1):
if ws.cell(row=i,column=1).value==None:break
print(ws.cell(row=i,column=1).value,ws.cell(row=i,column=2).value,ws.cell(row=i,column=3).value)
值(信用卡号输入)进行验证,在ts文件上获得input
值,并在用户仍第二次键入时检查API的验证input
,我的第一个输入值的示例:input
,因此我需要使用4444 4444 4444 4444
来获取前6个数字,然后再进行验证,
这是我尝试过的;
html文件
subString()
ts文件
<div>
<input
(keypress)="numberOnly($event)"
class="input"
type="text"
(keyup)="onKey($event)"
[(ngModel)]="creditCardNo"
/>
</div>
<div>
<input
class="input"
type="text"
[(ngModel)]="cardHolderName"
/>
</div>
使用 onKey(event) {
this.creditCardNo = event.target.value;
const test = this.creditCardNo
.replace(/\s/g, '')
.toString()
.substr(0, 6);
this.paymentService.getCreditCardDetail('JPJSMN', test).subscribe(res => {
if (!res) {
return;
}
console.log(res);
});
}
获取值更改,并根据收到的响应对ts文件进行验证,但是我注意到Im是否使用(keyup)="onKey($event)"
,它不会检测到复制和粘贴,并且会继续请求API,是否有更好的解决方案?
答案 0 :(得分:0)
您可以选择创建自定义的“ digitOnly” Angular指令。
有关如何执行此操作的出色指南,可以在这里找到: https://codeburst.io/digit-only-directive-in-angular-3db8a94d80c3
教程中显示的指令解决了复制和粘贴等问题。
答案 1 :(得分:0)
如果您只想在用户粘贴值时使用与编辑值相同的方式更新模型,则可以使用
(ngModelChange)="pasteEvent($event)"
<div>
<input
(keypress)="numberOnly($event)"
class="input"
type="text"
(ngModelChange)="pasteEventcreditCardNo(creditCardNo)"
[(ngModel)]="creditCardNo"
/>
</div>
<div>
<input
class="input"
type="text"
(ngModelChange)="pasteEventcardHolderName(cardHolderName)"
[(ngModel)]="cardHolderName"
/>
</div>