-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidation.js
More file actions
27 lines (27 loc) · 844 Bytes
/
Copy pathValidation.js
File metadata and controls
27 lines (27 loc) · 844 Bytes
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
jsx.Validation = {
regexpEmail: /[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-z]{2,7}/i,
trimRegexp: /(^[\s\xA0]+|[\s\xA0]+$)/g,
digitsRegexp: /\d+/,
isEmpty: function(data){
if (typeof data == 'string'){
return this.isEmptyString(data);
}else if (data.tagName.toLowerCase() == 'input' || data.tagName.toLowerCase() == 'textarea'){
return this.isEmptyInput(data);
}else if (data.tagName.toLowerCase() == 'select'){
return this.isEmptySelect(data);
}
},
isEmptyString: function(string){
return string.replace(this.trimRegexp, '') == '';
},
isEmptyInput: function(input){
return this.isEmptyString(input.value);
},
isEmptySelect: function(select){
return select.selectedIndex == 0;
},
isEmail: function(string){
return this.regexpEmail.test(string);
}
};
jsx.loaded('Validation');