1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-form.field.VTypes'>/**
2 </span> * @class Ext.form.field.VTypes
3 * <p>This is a singleton object which contains a set of commonly used field validation functions.
4 * The validations provided are basic and intended to be easily customizable and extended.</p>
5 * <p>To add custom VTypes specify the <code>{@link Ext.form.field.Text#vtype vtype}</code> validation
6 * test function, and optionally specify any corresponding error text to display and any keystroke
7 * filtering mask to apply. For example:</p>
8 * <pre><code>
9 // custom Vtype for vtype:'time'
10 var timeTest = /^([1-9]|1[0-9]):([0-5][0-9])(\s[a|p]m)$/i;
11 Ext.apply(Ext.form.field.VTypes, {
12 // vtype validation function
13 time: function(val, field) {
14 return timeTest.test(val);
16 // vtype Text property: The error text to display when the validation function returns false
17 timeText: 'Not a valid time. Must be in the format "12:34 PM".',
18 // vtype Mask property: The keystroke filter mask
19 timeMask: /[\d\s:amp]/i
21 * </code></pre>
23 * <pre><code>
24 // custom Vtype for vtype:'IPAddress'
25 Ext.apply(Ext.form.field.VTypes, {
26 IPAddress: function(v) {
27 return /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(v);
29 IPAddressText: 'Must be a numeric IP address',
30 IPAddressMask: /[\d\.]/i
32 * </code></pre>
35 Ext.define('Ext.form.field.VTypes', (function(){
36 // closure these in so they are only created once.
37 var alpha = /^[a-zA-Z_]+$/,
38 alphanum = /^[a-zA-Z0-9_]+$/,
39 email = /^(\w+)([\-+.][\w]+)*@(\w[\-\w]*\.){1,5}([A-Za-z]){2,6}$/,
40 url = /(((^https?)|(^ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
42 // All these messages and functions are configurable
45 alternateClassName: 'Ext.form.VTypes',
47 <span id='Ext-form.field.VTypes-method-email'> /**
48 </span> * The function used to validate email addresses. Note that this is a very basic validation -- complete
49 * validation per the email RFC specifications is very complex and beyond the scope of this class, although
50 * this function can be overridden if a more comprehensive validation scheme is desired. See the validation
51 * section of the <a href="http://en.wikipedia.org/wiki/E-mail_address">Wikipedia article on email addresses</a>
52 * for additional information. This implementation is intended to validate the following emails:<tt>
53 * 'barney@example.de', 'barney.rubble@example.com', 'barney-rubble@example.coop', 'barney+rubble@example.com'
55 * @param {String} value The email address
56 * @return {Boolean} true if the RegExp test passed, and false if not.
58 'email' : function(v){
61 <span id='Ext-form.field.VTypes-property-emailText'> /**
62 </span> * The error text to display when the email validation function returns false. Defaults to:
63 * <tt>'This field should be an e-mail address in the format "user@example.com"'</tt>
66 'emailText' : 'This field should be an e-mail address in the format "user@example.com"',
67 <span id='Ext-form.field.VTypes-property-emailMask'> /**
68 </span> * The keystroke filter mask to be applied on email input. See the {@link #email} method for
69 * information about more complex email validation. Defaults to:
70 * <tt>/[a-z0-9_\.\-@]/i</tt>
73 'emailMask' : /[a-z0-9_\.\-@\+]/i,
75 <span id='Ext-form.field.VTypes-method-url'> /**
76 </span> * The function used to validate URLs
77 * @param {String} value The URL
78 * @return {Boolean} true if the RegExp test passed, and false if not.
83 <span id='Ext-form.field.VTypes-property-urlText'> /**
84 </span> * The error text to display when the url validation function returns false. Defaults to:
85 * <tt>'This field should be a URL in the format "http:/'+'/www.example.com"'</tt>
88 'urlText' : 'This field should be a URL in the format "http:/'+'/www.example.com"',
90 <span id='Ext-form.field.VTypes-method-alpha'> /**
91 </span> * The function used to validate alpha values
92 * @param {String} value The value
93 * @return {Boolean} true if the RegExp test passed, and false if not.
95 'alpha' : function(v){
98 <span id='Ext-form.field.VTypes-property-alphaText'> /**
99 </span> * The error text to display when the alpha validation function returns false. Defaults to:
100 * <tt>'This field should only contain letters and _'</tt>
103 'alphaText' : 'This field should only contain letters and _',
104 <span id='Ext-form.field.VTypes-property-alphaMask'> /**
105 </span> * The keystroke filter mask to be applied on alpha input. Defaults to:
106 * <tt>/[a-z_]/i</tt>
109 'alphaMask' : /[a-z_]/i,
111 <span id='Ext-form.field.VTypes-method-alphanum'> /**
112 </span> * The function used to validate alphanumeric values
113 * @param {String} value The value
114 * @return {Boolean} true if the RegExp test passed, and false if not.
116 'alphanum' : function(v){
117 return alphanum.test(v);
119 <span id='Ext-form.field.VTypes-property-alphanumText'> /**
120 </span> * The error text to display when the alphanumeric validation function returns false. Defaults to:
121 * <tt>'This field should only contain letters, numbers and _'</tt>
124 'alphanumText' : 'This field should only contain letters, numbers and _',
125 <span id='Ext-form.field.VTypes-property-alphanumMask'> /**
126 </span> * The keystroke filter mask to be applied on alphanumeric input. Defaults to:
127 * <tt>/[a-z0-9_]/i</tt>
130 'alphanumMask' : /[a-z0-9_]/i
133 </pre></pre></body></html>