7

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'}]
  }
Fazil
  • 1,390
  • 2
  • 13
  • 26

4 Answers4

19

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

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

No need for regex.

Automatix
  • 789
  • 7
  • 7
  • 3
    There is no vtype in Sencha Touch – A.W. Sep 07 '14 at 14:41
  • There actually is and @gambetti's example is perfectly valid. I'm not sure since when it is available but have a look at http://docs.sencha.com/extjs/4.0.7/#!/api/Ext.form.field.Text-cfg-vtype and http://docs.sencha.com/extjs/4.0.7/#!/api/Ext.form.field.VTypes – maryisdead Feb 07 '17 at 09:16
5

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.

Viswa
  • 3,211
  • 5
  • 34
  • 65
5

For form field validation on user input use the following regex

{
  xtype: 'textfield',
  allowBlank:false,
  regex:/^((([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z\s?]{2,5}){1,25})*(\s*?;\s*?)*)*$/,
  regexText:'This field must contain single or multiple valid email addresses separated by semicolon (;)',
  blankText : 'Please enter email address(s)',
}
Hisham Javed
  • 159
  • 2
  • 4
0

email like "name---99@mail.com" is correct and doesnt work with this regular expression:
"var ereg = /^\w+([-+.']\w+)@\w+([-.]\w+).\w+([-.]\w+)*$/;" correct example:

    {
      xtype: 'textfield',
      name: 'Email',
      maxLength: 255,
      readOnly: true,
      validator: function (enteredValue) {
         if (!RegExp(/^\w+(-+\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/).test(enteredValue)) {
         return 'Error, not an email format';
           }
      return true;
      }
    }
aksionik
  • 1
  • 2