1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
| /**
| * @example Form Validation
| *
| */
| Ext.require('Ext.form.Panel');
| Ext.require('Ext.form.field.Date');
| Ext.onReady(function() {
|
| var timeTest = /^([1-9]|1[0-9]):([0-5][0-9])(\s[a|p]m)$/i;
| Ext.apply(Ext.form.field.VTypes, {
| // vtype validation function
| time: function(val, field) {
| return timeTest.test(val);
| },
| // vtype Text property: The error text to display when the validation function returns false
| timeText: 'Not a valid time. Must be in the format "12:34 PM".',
| // vtype Mask property: The keystroke filter mask
| timeMask: /[\d\s:amp]/i
| });
|
| Ext.create('Ext.form.Panel', {
| renderTo: Ext.getBody(),
| title: 'User Form',
| height: 200,
| width: 280,
| bodyPadding: 10,
| defaultType: 'textfield',
| items: [
| {
| fieldLabel: 'First Name',
| name: 'firstName'
| },
| {
| fieldLabel: 'Last Name',
| name: 'lastName'
| },
| {
| fieldLabel: 'Email Address',
| name: 'email',
| vtype: 'email'
| },
| {
| xtype: 'datefield',
| fieldLabel: 'Date of Birth',
| name: 'birthDate',
| msgTarget: 'under', // location of the error message
| invalidText: '"{0}" bad. "{1}" good.' // custom error message
| },
| {
| fieldLabel: 'Last Login Time',
| name: 'loginTime',
| vtype: 'time' // using a custom validation type
| }
| ]
| });
|
| });
|
|