-
Notifications
You must be signed in to change notification settings - Fork 1
/
validattion.js
72 lines (70 loc) · 2.36 KB
/
validattion.js
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
;
var validateResult = 0;
$.extend({
//Validate all data length and type
validateDataLengthAndType: function (selector, length, type, messageSelector){
console.log('validateDataLengthAndType');
var pattern = /^[0-9]*$/;
var selectorElement= $('#' + selector);
var messageSelector = '.' + selector + messageSelector;
switch(type)
{
case 'int':
if(!pattern.test(selectorElement.val()) || parseInt(selectorElement.val()) > 2147483647){
$(messageSelector).show();
validateResult++;
}
break;
case 'tinyint':
switch(length){
case 1:
if((selectorElement.val() !== '0' && selectorElement.val() !== '1')){
$(messageSelector).show();
validateResult++;
}
break;
case 4:
if(!pattern.test(selectorElement.val()) || selectorElement.val() > 255){
$(messageSelector).show();
validateResult++;
}
break;
default:
break;
}
break;
case 'varchar':
if(typeof selectorElement.val() !== 'string' || selectorElement.val().length > length){
console.log(123);
$(messageSelector).show();
validateResult++;
}
break;
case 'char':
if(typeof selectorElement.val() !== 'string' || selectorElement.val().length !== length){
$(messageSelector).show();
validateResult++;
}
break;
default:
console.log('error: no this type !');
break;
}
return validateResult;
},
//get all form input data
getInputsData: function(obj){
var allDataList = {};
for (var key in obj){
//key should be id selector
allDataList = { key : $('#' + obj[key]).val() };
}
return allDataList;
console.log(allDataList);
},
//reset validation Selector: inputs' parent element
resetValidation: function(selector){
validateResult = 0;
$(selector + ' p').hide();
},
})