-
Notifications
You must be signed in to change notification settings - Fork 1
/
THRTextField.j
83 lines (72 loc) · 2.04 KB
/
THRTextField.j
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
@import <Foundation/CPObject.j>
@implementation THRTextField : CPTextField
{
int validationMask @accessors;
}
+ (THRTextField) textfieldWithPlaceholder:(CPString)aPlaceholder frame:(CGRectFrame)aFrame validationMask:(int)aMask
{
var textfield = [[THRTextField alloc] initWithFrame:aFrame];
if( textfield )
{
[textfield setPlaceholderString:aPlaceholder];
[textfield setEditable:YES];
textfield.validationMask=aMask;
[textfield setFont:[CPFont systemFontOfSize:15]];
}
return textfield;
}
+ (THRTextField) textfieldWithPlaceholder:(CPString)aPlaceholder frame:(CGRectFrame)aFrame validationMask:(int)aMask bindTo:(id) aController withKeyPath:(CPString)aKeyPath
{
var textfield = [THRTextField textfieldWithPlaceholder:aPlaceholder frame:aFrame validationMask:aMask];
if( textfield )
{
[textfield bind:@"objectValue" toObject:aController withKeyPath:aKeyPath options:nil];
}
return textfield;
}
- (THRTextField) copy
{
var newObject = [THRTextField textfieldWithPlaceholder:[self placeholderString] frame:[self frame] validationMask:validationMask];
return newObject;
}
- (CPString) validateValueSelf
{
}
- (void) insertNewline:(id) sender
{
[self validateValue];
}
- (void) insertTab:(id) sender
{
[self validateValue];
}
- (void) validateValue
{
var statusMessage = [self validateValueSelf];
if( [statusMessage length] )
{
CPLog(statusMessage);
}
}
@end
@implementation THRTextField_Email : THRTextField
{
}
- (CPString) validateValueSelf
{
var statusText = "";
var value = [self stringValue];
var matchPattern=new RegExp("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum)\b");
if( value.match(matchPattern) )
{
CPLog(@"OK");
}
if( !matchPattern.test(value) )
{
statusText="Devi inserire un indirizzo email valido"+value;
}
else
statusText="OK";
return statusText;
}
@end