Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Email validation sencha

How to check validation for email field in sencha touch?Here my code in application,Please help me to solve this

  {
        xtype: 'fieldset',
        items:[{
        xtype: 'emailfield',
        inputType:'email',
        labelWidth: '33%',
        label: 'Email',
        id:'emailId',     
        name: 'emailId',placeHolder:'emailId'}]
  }
like image 519
Fazil Avatar asked Oct 01 '13 07:10

Fazil


2 Answers

The proper way to activate validation directly in the view would be:

{
  xtype: 'textfield',
  name: 'email',
  vtype: 'email'
}

No need for regex.

like image 189
Automatix Avatar answered Oct 13 '22 05:10

Automatix


If you storing fields as model instance, you can do.

Ext.define('User', {
    extend: 'Ext.data.Model',

    config: {
        fields: [
            {name: 'name',  type: 'string'},
            {name: 'emailId',    type: 'string'}
            {name: 'phone', type: 'string'}
        ]
    },

    validations: [
       {type: 'presence', name: 'name',message:"Enter Name"},
       {type: 'format',   name: 'emailId', matcher: /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/, message:"Wrong Email Format"}
    ]
});

Or you can just match with regular expression

var ereg = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
var testResult = ereg.test(emailId);

testResult will be true or false based on validation.

like image 5
Viswa Avatar answered Oct 13 '22 04:10

Viswa