PDA

View Full Version : email regexp with display name



valititi
23 Dec 2010, 1:50 AM
i need a to create a vtype regexp for validation of a complete e-mail textfield.
values in it must be like :


"John Smith <john@server.com>"

thanks

Condor
23 Dec 2010, 4:06 AM
You could try:

/^([\w\s]+)\s*<(\w+)([\-+.][\w]+)*@(\w[\-\w]*\.){1,5}([A-Za-z]){2,6}>$/

valititi
23 Dec 2010, 4:30 AM
thanks for answer, condor. but this reg exp let me type absolutely anything... I maded like this :



Ext.form.VTypes['myMailVal'] = /^([\w\s]+)\s*<(\w+)([\-+.][\w]+)*@(\w[\-\w]*\.){1,5}([A-Za-z]){2,6}>$/;
Ext.form.VTypes['myMailMask']= /^([\w\s]+)\s*<(\w+)([\-+.][\w]+)*@(\w[\-\w]*\.){1,5}([A-Za-z]){2,6}>$/;
Ext.form.VTypes['myMail']=function(v){
return Ext.form.VTypes['myMailVal'].test(v);
}
and my textfield with

vtype:'myMail'

Condor
23 Dec 2010, 4:57 AM
Your myMailMask is wrong (it's used to check valid keystrokes and not the entire string).

Try:

myMailMask: /[a-z0-9_\.\-@\+]/i

valititi
23 Dec 2010, 5:05 AM
if i put this mask i cannot type "<", ">"...
and if Mask equals Val, is there any problem ? normally must not... i don't know...
and i if put no mask, there are not alert.... even if i type anything ...
:-(

please, can you paste the correct code for this vtype ? and if there are something specific to the textfield definitions ? this don't work anyway.
I need strings like :
"John Smith <john@server.com>"

Condor
23 Dec 2010, 5:15 AM
1. Add < and > to the mask.

2. No, mask and val are NOT the same (mask is used for a single character, val is used for the entire string).

valititi
23 Dec 2010, 5:23 AM
this works now condor. thanks !
:-)
but now, if i can correct validate "aaa bbb <aaa@ccc.dd>"
if cannot type normal simple mail adress, like "aa@bbb.cc"
:-)

Condor
23 Dec 2010, 5:49 AM
So you want something like:

myMailVal: /^(?:([\w\s]+)\s*<(\w+)([\-+.][\w]+)*@(\w[\-\w]*\.){1,5}([A-Za-z]){2,6}>|(\w+)([\-+.][\w]+)*@(\w[\-\w]*\.){1,5}([A-Za-z]){2,6})$/

valititi
23 Dec 2010, 5:56 AM
yesssssssssssssss. :-)
thanks Condor.

i added

\s,>
to mask, otherwise cannot type these.
and added some vals:

/^(?[\w\s
to myMailVal regexp...

mond
19 Jan 2011, 10:20 PM
Hi, is there any possible out come to display the error message in a message box?

Condor
20 Jan 2011, 12:33 AM
Hi, is there any possible out come to display the error message in a message box?

I don't understand. Please rephrase the question.

mond
20 Jan 2011, 12:46 AM
What im trying to say is when the user press the Ok button it triggers the email validation() and the message target will show in the message box.

like this:


var emailFormat = /^([\w\-\'\-]+)(\.[\w-\'\-]+)*@([\w\-]+\.){1,5}([A-Za-z]){2,4}$/;

if(Ext.getCmp('email_add').getValue() != emailFormat){
Ext.MessageBox.show({
title : 'e-Clearance',
msg : 'Invalid Email Address format',
width : 300,
buttons : Ext.MessageBox.OK,
icon : Ext.MessageBox.WARNING,
animEl : Ext.getBody()
})
Ext.getCmp('email_add').focus(true,500);
return false;
}

Condor
20 Jan 2011, 1:18 AM
Normal validation happens on keyup. You don't want to show a messagebox at that time.

I should do the extra check before the submit, e.g.

onSubmitClick: function(){
if (!Ext.getCmp('email_add').isValid()) {
Ext.MessageBox.show({
title : 'e-Clearance',
msg : 'Invalid Email Address format',
width : 300,
buttons : Ext.MessageBox.OK,
icon : Ext.MessageBox.WARNING,
animEl : Ext.getBody(),
fn : function(){
Ext.getCmp('email_add').focus();
}
});
return;
}
...
}

mond
20 Jan 2011, 1:35 AM
thanks!!!

valititi
20 Jan 2011, 2:54 AM
hi Mond !
Are you sure you post you question in the good thread ? :-) Why you don't make a new thread with this ? Anyway... To display the error message... Which of them ? Errors from and Ajax call ? Errors from client side JavaScript execution ? You can display it simpler alerts, you can display it in Ext alert. or in Ext Message Box...



Ext.Msg.show({
title:'yourTitle',
msg:errorCode, // depends on what you do...
icon:Ext.Msg.INFO,
buttons:Ext.Msg.OK
});
is this that you look for ?

silkcom
10 Apr 2014, 8:44 AM
I was looking through this post today, thanks for the regex :), however I cleaned up a few places and figured I'd post in case someone else came here after the fact.


^(?:([\w\s]+?)\s*<(\w+)([\-+.][\w]+)*@(\w[\-\w]*\.){1,5}([A-Za-z]{2,6})>|(\w+)([\-+.][\w]+)*@(\w[\-\w]*\.){1,5}([A-Za-z]{2,6}))$

It puts matches around things a little cleaner, and isn't greety around the name so trailing spaces are matched better. (example Silkcom <silkcom@myemailaddress.com> would match on "Silkcom " for the display name, the new one matches on "Silkcom", also it used to match on "m" for the last one, now it matches on "com")

This matches on
email@address.com
Display Name<email@address.com>
Display Name <email@address.com>
email@address.co

but not on
email@address.c (not a real registrar)
Display<not an email@address.com> (spaces in email address)
And other not email address things.