How to validate email in Sencha using listener
To do that add listener
listeners: [
{
fn: 'onHomeTelephonefieldBlur',//name of fxn
event: 'blur',//textfield event
delegate: '#txt_customer_home_telephone'//id of field Home telephone
},
{
fn: 'onCustomerMobilefieldBlur',//name of fxn
event: 'blur',//textfield event
delegate: '#txt_customer_mobile'/id of field CustomerMobile
},
{
fn: 'onEmailfieldBlur',
event: 'blur',
delegate: '#txt_customer_email'
}
]
},
onHomeTelephonefieldBlur: function (textfield, e, eOpts) {
if (textfield.getValue() === '') {
Ext.Msg.alert("Home Telephone can't be empty");
textfield.setFocus(true);
}
var val = textfield.getValue();
if (val.search("[0-9]+") == -1)
Ext.Msg.alert("Error", "Invalid Telephone Number!!");
},
onCustomerMobilefieldBlur: function (textfield, e, eOpts) {
if (textfield.getValue() === '') {
Ext.Msg.alert("Customer Mobile can't be empty");
textfield.setFocus(true);
}
var val = textfield.getValue();
if (val.search("[0-9]+") == -1)
Ext.Msg.alert("Error", "Invalid Mobile Number!!");
},
onEmailfieldBlur: function (textfield, e, eOpts) {
if (textfield.getValue() === '') {
Ext.Msg.alert("Email can't be empty");
textfield.setFocus(true);
}
var val = textfield.getValue();
if (val.search("[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+[.][a-zA-Z]+") == -1)
Ext.Msg.alert("Error", "Invalid e-mail address!!");
},
To do that add listener
listeners: [
{
fn: 'onHomeTelephonefieldBlur',//name of fxn
event: 'blur',//textfield event
delegate: '#txt_customer_home_telephone'//id of field Home telephone
},
{
fn: 'onCustomerMobilefieldBlur',//name of fxn
event: 'blur',//textfield event
delegate: '#txt_customer_mobile'/id of field CustomerMobile
},
{
fn: 'onEmailfieldBlur',
event: 'blur',
delegate: '#txt_customer_email'
}
]
},
onHomeTelephonefieldBlur: function (textfield, e, eOpts) {
if (textfield.getValue() === '') {
Ext.Msg.alert("Home Telephone can't be empty");
textfield.setFocus(true);
}
var val = textfield.getValue();
if (val.search("[0-9]+") == -1)
Ext.Msg.alert("Error", "Invalid Telephone Number!!");
},
onCustomerMobilefieldBlur: function (textfield, e, eOpts) {
if (textfield.getValue() === '') {
Ext.Msg.alert("Customer Mobile can't be empty");
textfield.setFocus(true);
}
var val = textfield.getValue();
if (val.search("[0-9]+") == -1)
Ext.Msg.alert("Error", "Invalid Mobile Number!!");
},
onEmailfieldBlur: function (textfield, e, eOpts) {
if (textfield.getValue() === '') {
Ext.Msg.alert("Email can't be empty");
textfield.setFocus(true);
}
var val = textfield.getValue();
if (val.search("[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+[.][a-zA-Z]+") == -1)
Ext.Msg.alert("Error", "Invalid e-mail address!!");
},
This validation is done in sencha touch 2.2.1
ReplyDelete