source: trunk/web/addons/job_monarch/lib/extjs/source/widgets/form/VTypes.js @ 619

Last change on this file since 619 was 619, checked in by ramonb, 15 years ago

lib/:

  • added new AJAX dependancies: ExtJS, pChart, Lightbox2
File size: 3.8 KB
Line 
1/*
2 * Ext JS Library 2.2.1
3 * Copyright(c) 2006-2009, Ext JS, LLC.
4 * licensing@extjs.com
5 *
6 * http://extjs.com/license
7 */
8
9/**
10 * @class Ext.form.VTypes
11 * 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. To add
13 * your own custom VType:<pre><code>
14Ext.apply(Ext.form.VTypes, {
15    IPAddress:  function(v) {
16        return /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(v);
17    },
18    IPAddressText: 'Must be a numeric IP address'
19});
20</code></pre>
21 * @singleton
22 */
23Ext.form.VTypes = function(){
24    // closure these in so they are only created once.
25    var alpha = /^[a-zA-Z_]+$/;
26    var alphanum = /^[a-zA-Z0-9_]+$/;
27    var email = /^([\w]+)(\.[\w]+)*@([\w\-]+\.){1,5}([A-Za-z]){2,4}$/;
28    var url = /(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
29
30    // All these messages and functions are configurable
31    return {
32        /**
33         * The function used to validate email addresses.  Note that this is a very basic validation -- complete
34         * validation per the email RFC specifications is very complex and beyond the scope of this class, although
35         * this function can be overridden if a more comprehensive validation scheme is desired.  See the validation
36         * section of the <a href="http://en.wikipedia.org/wiki/E-mail_address">Wikipedia article on email addresses</a>
37         * for additional information.
38         * @param {String} value The email address
39         */
40        'email' : function(v){
41            return email.test(v);
42        },
43        /**
44         * The error text to display when the email validation function returns false
45         * @type String
46         */
47        'emailText' : 'This field should be an e-mail address in the format "user@domain.com"',
48        /**
49         * The keystroke filter mask to be applied on email input.  See the {@link #email} method for
50         * information about more complex email validation.
51         * @type RegExp
52         */
53        'emailMask' : /[a-z0-9_\.\-@]/i,
54
55        /**
56         * The function used to validate URLs
57         * @param {String} value The URL
58         */
59        'url' : function(v){
60            return url.test(v);
61        },
62        /**
63         * The error text to display when the url validation function returns false
64         * @type String
65         */
66        'urlText' : 'This field should be a URL in the format "http:/'+'/www.domain.com"',
67       
68        /**
69         * The function used to validate alpha values
70         * @param {String} value The value
71         */
72        'alpha' : function(v){
73            return alpha.test(v);
74        },
75        /**
76         * The error text to display when the alpha validation function returns false
77         * @type String
78         */
79        'alphaText' : 'This field should only contain letters and _',
80        /**
81         * The keystroke filter mask to be applied on alpha input
82         * @type RegExp
83         */
84        'alphaMask' : /[a-z_]/i,
85
86        /**
87         * The function used to validate alphanumeric values
88         * @param {String} value The value
89         */
90        'alphanum' : function(v){
91            return alphanum.test(v);
92        },
93        /**
94         * The error text to display when the alphanumeric validation function returns false
95         * @type String
96         */
97        'alphanumText' : 'This field should only contain letters, numbers and _',
98        /**
99         * The keystroke filter mask to be applied on alphanumeric input
100         * @type RegExp
101         */
102        'alphanumMask' : /[a-z0-9_]/i
103    };
104}();
Note: See TracBrowser for help on using the repository browser.