initial import
[roojs1] / Roo / form / VTypes.js
1 /*
2  * Based on:
3  * Ext JS Library 1.1.1
4  * Copyright(c) 2006-2007, Ext JS, LLC.
5  *
6  * Originally Released Under LGPL - original licence link has changed is not relivant.
7  *
8  * Fork - LGPL
9  * <script type="text/javascript">
10  */
11 /**
12  * @class Roo.form.VTypes
13  * Overridable validation definitions. The validations provided are basic and intended to be easily customizable and extended.
14  * @singleton
15  */
16 Roo.form.VTypes = function(){
17     // closure these in so they are only created once.
18     var alpha = /^[a-zA-Z_]+$/;
19     var alphanum = /^[a-zA-Z0-9_]+$/;
20     var email = /^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,4}$/;
21     var url = /(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
22
23     // All these messages and functions are configurable
24     return {
25         /**
26          * The function used to validate email addresses
27          * @param {String} value The email address
28          */
29         'email' : function(v){
30             return email.test(v);
31         },
32         /**
33          * The error text to display when the email validation function returns false
34          * @type String
35          */
36         'emailText' : 'This field should be an e-mail address in the format "user@domain.com"',
37         /**
38          * The keystroke filter mask to be applied on email input
39          * @type RegExp
40          */
41         'emailMask' : /[a-z0-9_\.\-@]/i,
42
43         /**
44          * The function used to validate URLs
45          * @param {String} value The URL
46          */
47         'url' : function(v){
48             return url.test(v);
49         },
50         /**
51          * The error text to display when the url validation function returns false
52          * @type String
53          */
54         'urlText' : 'This field should be a URL in the format "http:/'+'/www.domain.com"',
55         
56         /**
57          * The function used to validate alpha values
58          * @param {String} value The value
59          */
60         'alpha' : function(v){
61             return alpha.test(v);
62         },
63         /**
64          * The error text to display when the alpha validation function returns false
65          * @type String
66          */
67         'alphaText' : 'This field should only contain letters and _',
68         /**
69          * The keystroke filter mask to be applied on alpha input
70          * @type RegExp
71          */
72         'alphaMask' : /[a-z_]/i,
73
74         /**
75          * The function used to validate alphanumeric values
76          * @param {String} value The value
77          */
78         'alphanum' : function(v){
79             return alphanum.test(v);
80         },
81         /**
82          * The error text to display when the alphanumeric validation function returns false
83          * @type String
84          */
85         'alphanumText' : 'This field should only contain letters, numbers and _',
86         /**
87          * The keystroke filter mask to be applied on alphanumeric input
88          * @type RegExp
89          */
90         'alphanumMask' : /[a-z0-9_]/i
91     };
92 }();