PDA

View Full Version : Email Vtype and blanks



Bucs
9 Jun 2010, 7:03 AM
Trying to allow blanks in an email field, but if something IS entered, I want to validate against the standard email vtype. I have set allowBlank: true on the field...but it is invalidating the field if left blank.

Field config:


xtype: 'textfield',
id: 'reg_prof_txt_Email',
name: 'Email',
fieldLabel: 'Email',
anchor: '100%',
tabIndex: 4,
vtype: 'email',
allowBlank: true,
I can alter the source to change the vtype to make this work by changing the standard email vtype expression as follows:



email = /^((\w+)([\-+.][\w]+)*@(\w[\-\w]*\.){1,5}([A-Za-z]){2,6})*$/,
Without this, the allowBlank: true will never work. Shouldn't the expression always allow blanks so you can use the allowBlank config property to set it as you want?

In any event, instead of changing the source, I was trying to create my own vtype, which I am doing for many other fields, but it simply won't perform the validation. It allows blanks, but does not invalidate invalid entries....and I am using the same expression as the source:

The config and vtype definition are as follows:



field config:
------------------
xtype: 'textfield',
id: 'reg_prof_txt_Email',
name: 'Email',
fieldLabel: 'Email',
anchor: '100%',
tabIndex: 4,
vtype: 'emailOrBlank',
allowBlank: true,

vtype
-----------------
Ext.apply(Ext.form.VTypes, {
emailOrBlank: function(v) {
return /^(\w+)([\-+.][\w]+)*@(\w[\-\w]*\.){1,5}([A-Za-z]){2,6}$/.test(v);
},
emailOrBlank: 'This is not a valid email address.',
emailOrBlank: /[[0-9a-zA-Z-\@.]/
});
It is not even attempting the validation it appears, but only for this vtype. Other vtypes in the same vtype file declared the same way are working. What am I missing here...doing something wrong? I do have listeners on the field for focus and change, but I have removed them and get the same result.

Thanks for any help...


UPDATE: I'm and ***** and got bit by the ole Copy and Paste bug. Did not do the Text and Mask properties right....need to be emailOrBlankText and emailOrBlankMask...otherwise the vtype was validation against the Mask regex.

vitolini
10 Jan 2011, 12:03 PM
Can you post your final working solution please? I am going through the same problem...

Thanks

Bucs
10 Jan 2011, 12:28 PM
This was from quite some time ago so not sure where the final code even is...but I think I remember what the problem was, and it was a dumb cut and paste error which is probably not gong to help you. But in any event, look at my code for the vtype, I used the same property name for the mask and text msg as I did for the actual reg ex expression, so the vtype was very confused. The vtype should be something like this:



var emailCustomRegEx = /^((\w+)([\-+.][\w]+)*@(\w[\-\w]*\.){1,5}([A-Za-z]){2,6})*$/;
Ext.apply(Ext.form.VTypes, {
'emailCustom': function(v) {
return emailCustomRegEx.test(v);
},
'emailCustomText' : 'This field should be an e-mail address in the format "[email protected]"',
'emailCustomMask' : /[a-z0-9_\.\[email protected]]/i
});

vitolini
12 Jan 2011, 10:26 AM
it helps, thanks

valititi
12 Jan 2011, 11:05 AM
// Reg-Exp for E-Mail inputs...
Ext.form.VTypes["myMailVTypeVal"] =
/^(?:([\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})$/;
Ext.form.VTypes["myMailVTypeMask"] =
/[a-z0-9_\.\s<>\[email protected]\+]/i;
Ext.form.VTypes["myMailVTypeText"] =
'Mail must be like:<br><b>John Smith &lt;[email protected]&gt;\</b><br>or a simple mail, like:<br><b>[email protected]</b>';
Ext.form.VTypes['myMailVType']=
function(v,o){return Ext.form.VTypes['myMailVTypeVal'].test(v);}and then use vtype:'myMailVType', for your email input fields.it accepts
"[email protected]"
or
"xx yy <[email protected]>"

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