Add condition in the inputs of a alert control


#1

Hi, I want to know if it’s possible to add condition in the inputs of a alert control. For example, I would like my user to be able to put only the words “lion” or “elephant” in the input. Otherwise this is considered to be false and we do not push the data into our database

addAnimal(){
let prompt = this.alertCtrl.create({
title: ‘Animal Name’,
message: “…”,
inputs: [
{
name: ‘espece’,
placeholder: ‘Espece’,
type: ‘text’
}
],
buttons: [
{
text: ‘Cancel’,
handler: data => {
console.log(‘Cancel clicked’);
}
},
{
text: ‘Save’,
handler: data => {
this.animals.push({
espece: data.espece,
});
}
}
]
});
prompt.present();
}

Your help would be greatly appreciated


#2
if (data.espece === 'lion' || data.espece === 'elephant') {
  this.animals.push(data);
}

#3

I will try thank you !