~cdparra/gelee/trunk

« back to all changes in this revision

Viewing changes to webui/ecosystem/workspace/extjs/docs/source/VTypes.html

  • Committer: parra
  • Date: 2010-03-15 15:56:56 UTC
  • Revision ID: svn-v4:ac5bba68-f036-4e09-846e-8f32731cc928:trunk/gelee:1448
merged gelee at svn

Show diffs side-by-side

added added

removed removed

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