2 * Ext JS Library 2.2.1
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
10 * @class Ext.form.VTypes
\r
11 * This is a singleton object which contains a set of commonly used field validation functions.
\r
12 * The validations provided are basic and intended to be easily customizable and extended. To add
\r
13 * your own custom VType:<pre><code>
\r
14 Ext.apply(Ext.form.VTypes, {
\r
15 IPAddress: function(v) {
\r
16 return /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(v);
\r
18 IPAddressText: 'Must be a numeric IP address'
\r
23 Ext.form.VTypes = function(){
\r
24 // closure these in so they are only created once.
\r
25 var alpha = /^[a-zA-Z_]+$/;
\r
26 var alphanum = /^[a-zA-Z0-9_]+$/;
\r
27 var email = /^([\w]+)(\.[\w]+)*@([\w\-]+\.){1,5}([A-Za-z]){2,4}$/;
\r
28 var url = /(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
\r
30 // All these messages and functions are configurable
\r
33 * The function used to validate email addresses. Note that this is a very basic validation -- complete
\r
34 * validation per the email RFC specifications is very complex and beyond the scope of this class, although
\r
35 * this function can be overridden if a more comprehensive validation scheme is desired. See the validation
\r
36 * section of the <a href="http://en.wikipedia.org/wiki/E-mail_address">Wikipedia article on email addresses</a>
\r
37 * for additional information.
\r
38 * @param {String} value The email address
\r
40 'email' : function(v){
\r
41 return email.test(v);
\r
44 * The error text to display when the email validation function returns false
\r
47 'emailText' : 'This field should be an e-mail address in the format "user@domain.com"',
\r
49 * The keystroke filter mask to be applied on email input. See the {@link #email} method for
\r
50 * information about more complex email validation.
\r
53 'emailMask' : /[a-z0-9_\.\-@]/i,
\r
56 * The function used to validate URLs
\r
57 * @param {String} value The URL
\r
59 'url' : function(v){
\r
63 * The error text to display when the url validation function returns false
\r
66 'urlText' : 'This field should be a URL in the format "http:/'+'/www.domain.com"',
\r
69 * The function used to validate alpha values
\r
70 * @param {String} value The value
\r
72 'alpha' : function(v){
\r
73 return alpha.test(v);
\r
76 * The error text to display when the alpha validation function returns false
\r
79 'alphaText' : 'This field should only contain letters and _',
\r
81 * The keystroke filter mask to be applied on alpha input
\r
84 'alphaMask' : /[a-z_]/i,
\r
87 * The function used to validate alphanumeric values
\r
88 * @param {String} value The value
\r
90 'alphanum' : function(v){
\r
91 return alphanum.test(v);
\r
94 * The error text to display when the alphanumeric validation function returns false
\r
97 'alphanumText' : 'This field should only contain letters, numbers and _',
\r
99 * The keystroke filter mask to be applied on alphanumeric input
\r
102 'alphanumMask' : /[a-z0-9_]/i
\r