3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
17 * @class Ext.data.validations
20 * <p>This singleton contains a set of validation functions that can be used to validate any type
21 * of data. They are most often used in {@link Ext.data.Model Models}, where they are automatically
22 * set up and executed.</p>
24 Ext.define('Ext.data.validations', {
28 * The default error message used when a presence validation fails
29 * @property presenceMessage
32 presenceMessage: 'must be present',
35 * The default error message used when a length validation fails
36 * @property lengthMessage
39 lengthMessage: 'is the wrong length',
42 * The default error message used when a format validation fails
43 * @property formatMessage
46 formatMessage: 'is the wrong format',
49 * The default error message used when an inclusion validation fails
50 * @property inclusionMessage
53 inclusionMessage: 'is not included in the list of acceptable values',
56 * The default error message used when an exclusion validation fails
57 * @property exclusionMessage
60 exclusionMessage: 'is not an acceptable value',
63 * Validates that the given value is present
64 * @param {Object} config Optional config object
65 * @param {Mixed} value The value to validate
66 * @return {Boolean} True if validation passed
68 presence: function(config, value) {
69 if (value === undefined) {
77 * Returns true if the given value is between the configured min and max values
78 * @param {Object} config Optional config object
79 * @param {String} value The value to validate
80 * @return {Boolean} True if the value passes validation
82 length: function(config, value) {
83 if (value === undefined) {
87 var length = value.length,
91 if ((min && length < min) || (max && length > max)) {
99 * Returns true if the given value passes validation against the configured {@link #matcher} regex
100 * @param {Object} config Optional config object
101 * @param {String} value The value to validate
102 * @return {Boolean} True if the value passes the format validation
104 format: function(config, value) {
105 return !!(config.matcher && config.matcher.test(value));
109 * Validates that the given value is present in the configured {@link #list}
110 * @param {String} value The value to validate
111 * @return {Boolean} True if the value is present in the list
113 inclusion: function(config, value) {
114 return config.list && Ext.Array.indexOf(config.list,value) != -1;
118 * Validates that the given value is present in the configured {@link #list}
119 * @param {Object} config Optional config object
120 * @param {String} value The value to validate
121 * @return {Boolean} True if the value is not present in the list
123 exclusion: function(config, value) {
124 return config.list && Ext.Array.indexOf(config.list,value) == -1;