]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | /**\r |
2 | * Validates that the passed value matches a specific format specified by a regex.\r | |
3 | * The format is provided by the {@link #matcher} config.\r | |
4 | */\r | |
5 | Ext.define('Ext.data.validator.Format', {\r | |
6 | extend: 'Ext.data.validator.Validator',\r | |
7 | alias: 'data.validator.format',\r | |
8 | \r | |
9 | type: 'format',\r | |
10 | \r | |
11 | config: {\r | |
12 | /**\r | |
13 | * @cfg {String} message\r | |
14 | * The error message to return when the value does not match the format.\r | |
15 | */\r | |
16 | message: 'Is in the wrong format',\r | |
17 | \r | |
18 | /**\r | |
19 | * @cfg {RegExp} matcher (required) The matcher regex to test against the value.\r | |
20 | */\r | |
21 | matcher: undefined\r | |
22 | },\r | |
23 | \r | |
24 | //<debug>\r | |
25 | constructor: function() {\r | |
26 | this.callParent(arguments);\r | |
27 | if (!this.getMatcher()) {\r | |
28 | Ext.raise('validator.Format must be configured with a matcher');\r | |
29 | }\r | |
30 | },\r | |
31 | //</debug>\r | |
32 | \r | |
33 | validate: function(value) {\r | |
34 | var matcher = this.getMatcher(),\r | |
35 | result = matcher && matcher.test(value);\r | |
36 | \r | |
37 | return result ? result : this.getMessage();\r | |
38 | }\r | |
39 | });\r |