PDA

View Full Version : Email validation on textfield



hamann71
25 Mar 2011, 3:23 AM
Hi there,

Is this the right way 2 check a email text field??

first i create the plugin

Ext.ux.validateEmailAddress=Ext.extend(Object,
{
init :
function(fld)
{

fld.on('blur',function(field)
{
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
//trim spaces
var newEmailAddress=field.getValue().replace(/^\s+|\s+$/g,"");
if(!reg.test(newEmailAddress) )
{

Ext.MessageBox.show(
{

msg:
'Ongeldig E-mailadres opgegeven!',
buttons:
Ext.MessageBox.OK,
animEl: 'mb9'
,
maxWidth:
300,
icon:
Ext.MessageBox.WARNING
}
);
field.markInvalid();
}

}
);
}
}
);



second i create the textfield with the plugin

{
fieldLabel: 'E-mailadres'
,
enableKeyEvents :
true,
id:'veld_9'
,
allowBlank:
false
,
name: 'veld_9'
,
plugins:
new Ext.ux.validateEmailAddress(),

width:
300
}

I wonder if this the right solution for checking a email on textfield?

moegal
25 Mar 2011, 3:54 AM
have you looked at vtypes?

hamann71
25 Mar 2011, 4:01 AM
have you looked at vtypes?

thanks for the intel

qooleot
29 Mar 2011, 12:11 PM
You just need vtype: 'email'

Also, this is the wrong forum for asking questions.