3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js"><div id="cls-Ext.form.VTypes"></div>/**
10 * @class Ext.form.VTypes
11 * <p>This is a singleton object which contains a set of commonly used field validation functions.
12 * The validations provided are basic and intended to be easily customizable and extended.</p>
13 * <p>To add custom VTypes specify the <code>{@link Ext.form.TextField#vtype vtype}</code> validation
14 * test function, and optionally specify any corresponding error text to display and any keystroke
15 * filtering mask to apply. For example:</p>
17 // custom Vtype for vtype:'time'
18 var timeTest = /^([1-9]|1[0-9]):([0-5][0-9])(\s[a|p]m)$/i;
19 Ext.apply(Ext.form.VTypes, {
20 // vtype validation function
21 time: function(val, field) {
22 return timeTest.test(val);
24 // vtype Text property: The error text to display when the validation function returns false
25 timeText: 'Not a valid time. Must be in the format "12:34 PM".',
26 // vtype Mask property: The keystroke filter mask
27 timeMask: /[\d\s:amp]/i
32 // custom Vtype for vtype:'IPAddress'
33 Ext.apply(Ext.form.VTypes, {
34 IPAddress: function(v) {
35 return /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(v);
37 IPAddressText: 'Must be a numeric IP address',
38 IPAddressMask: /[\d\.]/i
43 Ext.form.VTypes = function(){
44 // closure these in so they are only created once.
45 var alpha = /^[a-zA-Z_]+$/,
46 alphanum = /^[a-zA-Z0-9_]+$/,
47 email = /^(\w+)([\-+.][\w]+)*@(\w[\-\w]*\.){1,5}([A-Za-z]){2,6}$/,
48 url = /(((^https?)|(^ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
50 // All these messages and functions are configurable
52 <div id="method-Ext.form.VTypes-email"></div>/**
53 * The function used to validate email addresses. Note that this is a very basic validation -- complete
54 * validation per the email RFC specifications is very complex and beyond the scope of this class, although
55 * this function can be overridden if a more comprehensive validation scheme is desired. See the validation
56 * section of the <a href="http://en.wikipedia.org/wiki/E-mail_address">Wikipedia article on email addresses</a>
57 * for additional information. This implementation is intended to validate the following emails:<tt>
58 * 'barney@example.de', 'barney.rubble@example.com', 'barney-rubble@example.coop', 'barney+rubble@example.com'
60 * @param {String} value The email address
61 * @return {Boolean} true if the RegExp test passed, and false if not.
63 'email' : function(v){
66 <div id="prop-Ext.form.VTypes-emailText"></div>/**
67 * The error text to display when the email validation function returns false. Defaults to:
68 * <tt>'This field should be an e-mail address in the format "user@example.com"'</tt>
71 'emailText' : 'This field should be an e-mail address in the format "user@example.com"',
72 <div id="prop-Ext.form.VTypes-emailMask"></div>/**
73 * The keystroke filter mask to be applied on email input. See the {@link #email} method for
74 * information about more complex email validation. Defaults to:
75 * <tt>/[a-z0-9_\.\-@]/i</tt>
78 'emailMask' : /[a-z0-9_\.\-@]/i,
80 <div id="method-Ext.form.VTypes-url"></div>/**
81 * The function used to validate URLs
82 * @param {String} value The URL
83 * @return {Boolean} true if the RegExp test passed, and false if not.
88 <div id="prop-Ext.form.VTypes-urlText"></div>/**
89 * The error text to display when the url validation function returns false. Defaults to:
90 * <tt>'This field should be a URL in the format "http:/'+'/www.example.com"'</tt>
93 'urlText' : 'This field should be a URL in the format "http:/'+'/www.example.com"',
95 <div id="method-Ext.form.VTypes-alpha"></div>/**
96 * The function used to validate alpha values
97 * @param {String} value The value
98 * @return {Boolean} true if the RegExp test passed, and false if not.
100 'alpha' : function(v){
101 return alpha.test(v);
103 <div id="prop-Ext.form.VTypes-alphaText"></div>/**
104 * The error text to display when the alpha validation function returns false. Defaults to:
105 * <tt>'This field should only contain letters and _'</tt>
108 'alphaText' : 'This field should only contain letters and _',
109 <div id="prop-Ext.form.VTypes-alphaMask"></div>/**
110 * The keystroke filter mask to be applied on alpha input. Defaults to:
114 'alphaMask' : /[a-z_]/i,
116 <div id="method-Ext.form.VTypes-alphanum"></div>/**
117 * The function used to validate alphanumeric values
118 * @param {String} value The value
119 * @return {Boolean} true if the RegExp test passed, and false if not.
121 'alphanum' : function(v){
122 return alphanum.test(v);
124 <div id="prop-Ext.form.VTypes-alphanumText"></div>/**
125 * The error text to display when the alphanumeric validation function returns false. Defaults to:
126 * <tt>'This field should only contain letters, numbers and _'</tt>
129 'alphanumText' : 'This field should only contain letters, numbers and _',
130 <div id="prop-Ext.form.VTypes-alphanumMask"></div>/**
131 * The keystroke filter mask to be applied on alphanumeric input. Defaults to:
132 * <tt>/[a-z0-9_]/i</tt>
135 'alphanumMask' : /[a-z0-9_]/i