1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-data.validations'>/**
2 </span> * @author Ed Spencer
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', {
13 <span id='Ext-data.validations-property-presenceMessage'> /**
14 </span> * The default error message used when a presence validation fails
15 * @property presenceMessage
18 presenceMessage: 'must be present',
20 <span id='Ext-data.validations-property-lengthMessage'> /**
21 </span> * The default error message used when a length validation fails
22 * @property lengthMessage
25 lengthMessage: 'is the wrong length',
27 <span id='Ext-data.validations-property-formatMessage'> /**
28 </span> * The default error message used when a format validation fails
29 * @property formatMessage
32 formatMessage: 'is the wrong format',
34 <span id='Ext-data.validations-property-inclusionMessage'> /**
35 </span> * The default error message used when an inclusion validation fails
36 * @property inclusionMessage
39 inclusionMessage: 'is not included in the list of acceptable values',
41 <span id='Ext-data.validations-property-exclusionMessage'> /**
42 </span> * The default error message used when an exclusion validation fails
43 * @property exclusionMessage
46 exclusionMessage: 'is not an acceptable value',
48 <span id='Ext-data.validations-method-presence'> /**
49 </span> * 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) {
62 <span id='Ext-data.validations-method-length'> /**
63 </span> * 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)) {
84 <span id='Ext-data.validations-method-format'> /**
85 </span> * 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));
94 <span id='Ext-data.validations-method-inclusion'> /**
95 </span> * 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;
103 <span id='Ext-data.validations-method-exclusion'> /**
104 </span> * 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;
112 });</pre></pre></body></html>