4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-form-field-VTypes'>/**
19 </span> * @class Ext.form.field.VTypes
20 * <p>This is a singleton object which contains a set of commonly used field validation functions.
21 * The validations provided are basic and intended to be easily customizable and extended.</p>
22 * <p>To add custom VTypes specify the <code>{@link Ext.form.field.Text#vtype vtype}</code> validation
23 * test function, and optionally specify any corresponding error text to display and any keystroke
24 * filtering mask to apply. For example:</p>
25 * <pre><code>
26 // custom Vtype for vtype:'time'
27 var timeTest = /^([1-9]|1[0-9]):([0-5][0-9])(\s[a|p]m)$/i;
28 Ext.apply(Ext.form.field.VTypes, {
29 // vtype validation function
30 time: function(val, field) {
31 return timeTest.test(val);
33 // vtype Text property: The error text to display when the validation function returns false
34 timeText: 'Not a valid time. Must be in the format "12:34 PM".',
35 // vtype Mask property: The keystroke filter mask
36 timeMask: /[\d\s:amp]/i
38 * </code></pre>
40 * <pre><code>
41 // custom Vtype for vtype:'IPAddress'
42 Ext.apply(Ext.form.field.VTypes, {
43 IPAddress: function(v) {
44 return /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(v);
46 IPAddressText: 'Must be a numeric IP address',
47 IPAddressMask: /[\d\.]/i
49 * </code></pre>
52 Ext.define('Ext.form.field.VTypes', (function(){
53 // closure these in so they are only created once.
54 var alpha = /^[a-zA-Z_]+$/,
55 alphanum = /^[a-zA-Z0-9_]+$/,
56 email = /^(\w+)([\-+.][\w]+)*@(\w[\-\w]*\.){1,5}([A-Za-z]){2,6}$/,
57 url = /(((^https?)|(^ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
59 // All these messages and functions are configurable
62 alternateClassName: 'Ext.form.VTypes',
64 <span id='Ext-form-field-VTypes-method-email'> /**
65 </span> * The function used to validate email addresses. Note that this is a very basic validation -- complete
66 * validation per the email RFC specifications is very complex and beyond the scope of this class, although
67 * this function can be overridden if a more comprehensive validation scheme is desired. See the validation
68 * section of the <a href="http://en.wikipedia.org/wiki/E-mail_address">Wikipedia article on email addresses</a>
69 * for additional information. This implementation is intended to validate the following emails:<tt>
70 * 'barney@example.de', 'barney.rubble@example.com', 'barney-rubble@example.coop', 'barney+rubble@example.com'
72 * @param {String} value The email address
73 * @return {Boolean} true if the RegExp test passed, and false if not.
75 'email' : function(v){
78 <span id='Ext-form-field-VTypes-property-emailText'> /**
79 </span> * The error text to display when the email validation function returns false. Defaults to:
80 * <tt>'This field should be an e-mail address in the format "user@example.com"'</tt>
83 'emailText' : 'This field should be an e-mail address in the format "user@example.com"',
84 <span id='Ext-form-field-VTypes-property-emailMask'> /**
85 </span> * The keystroke filter mask to be applied on email input. See the {@link #email} method for
86 * information about more complex email validation. Defaults to:
87 * <tt>/[a-z0-9_\.\-@]/i</tt>
90 'emailMask' : /[a-z0-9_\.\-@\+]/i,
92 <span id='Ext-form-field-VTypes-method-url'> /**
93 </span> * The function used to validate URLs
94 * @param {String} value The URL
95 * @return {Boolean} true if the RegExp test passed, and false if not.
100 <span id='Ext-form-field-VTypes-property-urlText'> /**
101 </span> * The error text to display when the url validation function returns false. Defaults to:
102 * <tt>'This field should be a URL in the format "http:/'+'/www.example.com"'</tt>
105 'urlText' : 'This field should be a URL in the format "http:/'+'/www.example.com"',
107 <span id='Ext-form-field-VTypes-method-alpha'> /**
108 </span> * The function used to validate alpha values
109 * @param {String} value The value
110 * @return {Boolean} true if the RegExp test passed, and false if not.
112 'alpha' : function(v){
113 return alpha.test(v);
115 <span id='Ext-form-field-VTypes-property-alphaText'> /**
116 </span> * The error text to display when the alpha validation function returns false. Defaults to:
117 * <tt>'This field should only contain letters and _'</tt>
120 'alphaText' : 'This field should only contain letters and _',
121 <span id='Ext-form-field-VTypes-property-alphaMask'> /**
122 </span> * The keystroke filter mask to be applied on alpha input. Defaults to:
123 * <tt>/[a-z_]/i</tt>
126 'alphaMask' : /[a-z_]/i,
128 <span id='Ext-form-field-VTypes-method-alphanum'> /**
129 </span> * The function used to validate alphanumeric values
130 * @param {String} value The value
131 * @return {Boolean} true if the RegExp test passed, and false if not.
133 'alphanum' : function(v){
134 return alphanum.test(v);
136 <span id='Ext-form-field-VTypes-property-alphanumText'> /**
137 </span> * The error text to display when the alphanumeric validation function returns false. Defaults to:
138 * <tt>'This field should only contain letters, numbers and _'</tt>
141 'alphanumText' : 'This field should only contain letters, numbers and _',
142 <span id='Ext-form-field-VTypes-property-alphanumMask'> /**
143 </span> * The keystroke filter mask to be applied on alphanumeric input. Defaults to:
144 * <tt>/[a-z0-9_]/i</tt>
147 'alphanumMask' : /[a-z0-9_]/i