3 * @class Ext.data.validations
6 * <p>This singleton contains a set of validation functions that can be used to validate any type
7 * of data. They are most often used in {@link Ext.data.Model Models}, where they are automatically
8 * set up and executed.</p>
10 Ext.define('Ext.data.validations', {
14 * The default error message used when a presence validation fails
15 * @property presenceMessage
18 presenceMessage: 'must be present',
21 * The default error message used when a length validation fails
22 * @property lengthMessage
25 lengthMessage: 'is the wrong length',
28 * The default error message used when a format validation fails
29 * @property formatMessage
32 formatMessage: 'is the wrong format',
35 * The default error message used when an inclusion validation fails
36 * @property inclusionMessage
39 inclusionMessage: 'is not included in the list of acceptable values',
42 * The default error message used when an exclusion validation fails
43 * @property exclusionMessage
46 exclusionMessage: 'is not an acceptable value',
49 * Validates that the given value is present
50 * @param {Object} config Optional config object
51 * @param {Mixed} value The value to validate
52 * @return {Boolean} True if validation passed
54 presence: function(config, value) {
55 if (value === undefined) {
63 * Returns true if the given value is between the configured min and max values
64 * @param {Object} config Optional config object
65 * @param {String} value The value to validate
66 * @return {Boolean} True if the value passes validation
68 length: function(config, value) {
69 if (value === undefined) {
73 var length = value.length,
77 if ((min && length < min) || (max && length > max)) {
85 * Returns true if the given value passes validation against the configured {@link #matcher} regex
86 * @param {Object} config Optional config object
87 * @param {String} value The value to validate
88 * @return {Boolean} True if the value passes the format validation
90 format: function(config, value) {
91 return !!(config.matcher && config.matcher.test(value));
95 * Validates that the given value is present in the configured {@link #list}
96 * @param {String} value The value to validate
97 * @return {Boolean} True if the value is present in the list
99 inclusion: function(config, value) {
100 return config.list && Ext.Array.indexOf(config.list,value) != -1;
104 * Validates that the given value is present in the configured {@link #list}
105 * @param {Object} config Optional config object
106 * @param {String} value The value to validate
107 * @return {Boolean} True if the value is not present in the list
109 exclusion: function(config, value) {
110 return config.list && Ext.Array.indexOf(config.list,value) == -1;