[英]How to set the limit of input in AlertBox in ionic v3
So i'm creating an alert box,and it has some inputs,and i want to restrict that input to max 10 characters and also make sure only numbers are entered into it 所以我正在创建一个警报框,它有一些输入,并且我想将该输入限制为最多10个字符,并且还要确保仅在其中输入数字
I couldn't find any guides on that,any help would be appreciated 我找不到任何指导,不胜感激
> const alert = this.alertCtrl.create({
title: 'Please Enter your Mobile',
inputs: [
{
name: 'mobile',
placeholder: 'Mobile'
}
],
buttons: [
{
text: 'Done',
handler: data => {
if (data.mobile != "" || data.mobile != null) {
this.data3 = data.mobile;
this.storage.set('number',data.mobile);
}
else {
this.ionViewDidLoad();
}
}
}
]
});
alert.present();
Here's my code,i want to restrict the input field mobile to 10 characters and make it only take numerical values and also is it possible to check if its empty or not 这是我的代码,我想将输入字段限制为10个字符,并使其仅采用数字值,还可以检查其是否为空
You can use Toast
notification here. 您可以在此处使用
Toast
通知。
alert boxe's done
handler: 警报框的
done
处理程序:
{
text: 'Done',
handler: (data) => {
if (MyValidator.isValid(data.mobile)) {
if (this.data) {
//my code
} else {
//my code
}
return true;
} else {
this.showErrorToast('Invalid mobile');
return false;
}
}
}
Note: Here MyValidator
is a validation class where you can use according to your use case. 注意:这里
MyValidator
是一个验证类,您可以在其中根据用例使用它。
Toast
method is like this: Toast
方法是这样的:
showErrorToast(data: any) {
let toast = this.toastCtrl.create({
message: data,
duration: 3000,
position: 'top'
});
toast.onDidDismiss(() => {
console.log('Dismissed toast');
});
toast.present();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.