To add client side validation on a UniEdit with the error provider icon/red underline simply add the following code:
1) For an Email validation
UniEdit1 -> ClientEvents -> UniEvents add the following beforeinit code:
function beforeInit(sender, config)
{
Ext.apply(sender,{allowBlank:false,vtype:'email',msgTarget : 'side'});
}
2) For a custom Time validation on a UniEdit control add the following beforeinit code:
function beforeInit(sender, config)
{
var timeTest = /^([1-9]|1[0-9])[0-5][0-9])(\s[a|p]m)$/i;
Ext.apply(Ext.form.field.VTypes, {
// vtype validation function
time: function(val, field) {
return timeTest.test(val);
},
// vtype Text property: The error text to display when the validation function returns false
timeText: 'Not a valid time. Must be in the format "12:34 PM".',
// vtype Mask property: The keystroke filter mask
timeMask: /[\d\s:amp]/i
});
Ext.apply(sender,{
name: 'departureTime',
vtype: 'time',
msgTarget : 'side'
});
}
3) For client side IPAddress validation on a UniEdit do the following:
function beforeInit(sender, config)
{
// custom Vtype for vtype:'IPAddress'
Ext.apply(Ext.form.field.VTypes, {
IPAddress: function(v) {
return /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(v);
},
IPAddressText: 'Must be a numeric IP address',
IPAddressMask: /[\d\.]/i
});
Ext.apply(sender,{
name: 'IPAddress',
vtype: 'IPAddress',
msgTarget : 'side'
});
}
4) For clientside AlphaNum validation on a UniEdit do the following:
function beforeInit(sender, config)
{
// custom Vtype for vtype:'AlphaNum'
Ext.apply(Ext.form.field.VTypes, {
AlphaNum: function(v) {
return /^[a-zA-Z0-9_]+$/i.test(v);
},
AlphaNumText: 'Must be an alphanumeric word',
// This mask filter invalid keystrokes
AlphaNumMask: /[a-z0-9]/i
});
Ext.apply(sender,{
vtype: 'AlphaNum',
msgTarget : 'side'
});
}
5) For clientside URL validation on a UniEdit do the following:
function beforeInit(sender, config)
{
var url = /(((^https?)|(^ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@`~=%!]*)(\.\w{2,})?)*\/?)/i;
// custom Vtype for vtype:'url'
Ext.apply(Ext.form.field.VTypes, {
url: function(v) {
return url.test(v);
},
urlText: 'Must be a valid URL (ie. http, https or ftp)'
});
Ext.apply(sender,{
vtype: 'url',
msgTarget : 'side'
});
}
***Note*** msgTarget: 'side' shows the round red icon with the white exclamation mark in it.
Next step.. A UniEdit control with validation type = 'Email' or 'Time' or 'Date' or etc etc.. or 'Custom' with Regular expression. Min/Max length etc etc.