4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-data-validations'>/**
19 </span> * @author Ed Spencer
20 * @class Ext.data.validations
23 * <p>This singleton contains a set of validation functions that can be used to validate any type
24 * of data. They are most often used in {@link Ext.data.Model Models}, where they are automatically
25 * set up and executed.</p>
27 Ext.define('Ext.data.validations', {
30 <span id='Ext-data-validations-property-presenceMessage'> /**
31 </span> * The default error message used when a presence validation fails
32 * @property presenceMessage
35 presenceMessage: 'must be present',
37 <span id='Ext-data-validations-property-lengthMessage'> /**
38 </span> * The default error message used when a length validation fails
39 * @property lengthMessage
42 lengthMessage: 'is the wrong length',
44 <span id='Ext-data-validations-property-formatMessage'> /**
45 </span> * The default error message used when a format validation fails
46 * @property formatMessage
49 formatMessage: 'is the wrong format',
51 <span id='Ext-data-validations-property-inclusionMessage'> /**
52 </span> * The default error message used when an inclusion validation fails
53 * @property inclusionMessage
56 inclusionMessage: 'is not included in the list of acceptable values',
58 <span id='Ext-data-validations-property-exclusionMessage'> /**
59 </span> * The default error message used when an exclusion validation fails
60 * @property exclusionMessage
63 exclusionMessage: 'is not an acceptable value',
65 <span id='Ext-data-validations-method-presence'> /**
66 </span> * Validates that the given value is present
67 * @param {Object} config Optional config object
68 * @param {Mixed} value The value to validate
69 * @return {Boolean} True if validation passed
71 presence: function(config, value) {
72 if (value === undefined) {
79 <span id='Ext-data-validations-method-length'> /**
80 </span> * Returns true if the given value is between the configured min and max values
81 * @param {Object} config Optional config object
82 * @param {String} value The value to validate
83 * @return {Boolean} True if the value passes validation
85 length: function(config, value) {
86 if (value === undefined) {
90 var length = value.length,
94 if ((min && length < min) || (max && length > max)) {
101 <span id='Ext-data-validations-method-format'> /**
102 </span> * Returns true if the given value passes validation against the configured {@link #matcher} regex
103 * @param {Object} config Optional config object
104 * @param {String} value The value to validate
105 * @return {Boolean} True if the value passes the format validation
107 format: function(config, value) {
108 return !!(config.matcher && config.matcher.test(value));
111 <span id='Ext-data-validations-method-inclusion'> /**
112 </span> * Validates that the given value is present in the configured {@link #list}
113 * @param {String} value The value to validate
114 * @return {Boolean} True if the value is present in the list
116 inclusion: function(config, value) {
117 return config.list && Ext.Array.indexOf(config.list,value) != -1;
120 <span id='Ext-data-validations-method-exclusion'> /**
121 </span> * Validates that the given value is present in the configured {@link #list}
122 * @param {Object} config Optional config object
123 * @param {String} value The value to validate
124 * @return {Boolean} True if the value is not present in the list
126 exclusion: function(config, value) {
127 return config.list && Ext.Array.indexOf(config.list,value) == -1;