Merge branch 'master' of http://git.roojs.com/roojs1
[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  * @static
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,24}$/;
21     var url = /^(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
22     var urlWeb = /^((https?):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
23
24     // All these messages and functions are configurable
25     return {
26         /**
27          * The function used to validate email addresses
28          * @param {String} value The email address
29          */
30         email : function(v){
31             return email.test(v);
32         },
33         /**
34          * The error text to display when the email validation function returns false
35          * @type String
36          */
37         emailText : 'This field should be an e-mail address in the format "user@domain.com"',
38         /**
39          * The keystroke filter mask to be applied on email input
40          * @type RegExp
41          */
42         emailMask : /[a-z0-9_\.\-@]/i,
43
44         /**
45          * The function used to validate URLs
46          * @param {String} value The URL
47          */
48         url : function(v){
49             return url.test(v);
50         },
51         /**
52          * The funciton used to validate URLs (only allow schemes 'https' and 'http')
53          * @param {String} v The URL
54          */
55         urlWeb : function(v) {
56             return urlWeb.test(v);
57         },
58         /**
59          * The error text to display when the url validation function returns false
60          * @type String
61          */
62         urlText : 'This field should be a URL in the format "http:/'+'/www.domain.com"',
63         
64         /**
65          * The function used to validate alpha values
66          * @param {String} value The value
67          */
68         alpha : function(v){
69             return alpha.test(v);
70         },
71         /**
72          * The error text to display when the alpha validation function returns false
73          * @type String
74          */
75         alphaText : 'This field should only contain letters and _',
76         /**
77          * The keystroke filter mask to be applied on alpha input
78          * @type RegExp
79          */
80         alphaMask : /[a-z_]/i,
81
82         /**
83          * The function used to validate alphanumeric values
84          * @param {String} value The value
85          */
86         alphanum : function(v){
87             return alphanum.test(v);
88         },
89         /**
90          * The error text to display when the alphanumeric validation function returns false
91          * @type String
92          */
93         alphanumText : 'This field should only contain letters, numbers and _',
94         /**
95          * The keystroke filter mask to be applied on alphanumeric input
96          * @type RegExp
97          */
98         alphanumMask : /[a-z0-9_]/i
99     };
100 }();