validationMethods.js
2.55 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
export default class Validation{
validateEmail (value) {
// regex from http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(value);
};
// containsNoSpecialCharacters(str){
// return !/[~`!#$%\^&*+=\-\[\]\\';,/{}|\\":<>\?]/g.test(str);
// }
noSpecialChars(str){
str = String(str);
return !/[~`!#$%\^&*+=\-\[\]\\';,/{}|\\":<>\?]/g.test(str);
}
noQwertysAllowed (str){
str = str.toLowerCase();
if(str.toLowerCase().indexOf("qwerty") >-1){
return false;
} else{
return true;
}
}
passwordValidation (str){
if(str.length <6){
return false;
} else{
return true;
}
}
isNumberOnly(str){
if(!/^\d+$/.test(str)){
return false;
}else {
return true;
}
}
isPositiveNotZeroNumber(str){
str = parseFloat(str);
if(str <=0){
return false;
}else {
return true;
}
}
isNumeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
isValidACN(str){
str = String(str);
//Remove any whitespace.
str = str.replace(/\s+/g, '');
console.log(str);
console.log(str.length);
if(/^\d+$/.test(str) && str.length ==9){
return true;
} else{
return false;
}
}
isValidShortCode(str){
str = String(str);
console.log(str);
if(str.length < 5 && str.length >2){
return true;
} else{
return false;
}
}
containsNumbers (str){
if(/\d/g.test(str)){
return true;
}else{
return false;
}
}
isInt(n){
console.log(typeof Number(n));
return Number(n) % 1 === 0;
}
isFloat(n){
return Number(n) % 1 !== 0;
}
decimalPlaces(num) {
num = parseFloat(num);
var match = (''+num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
if (!match) { return 0; }
return Math.max(
0,
// Number of digits right of decimal point.
(match[1] ? match[1].length : 0)
// Adjust for scientific notation.
- (match[2] ? +match[2] : 0));
}
notNull(input)
{
if (input.length == 0)
{
return false;
}
return true;
}
mobileNumber(txtMobId)
{
var IndNum = /^[0]?[789]\d{9}$/;
if(IndNum.test(txtMobId))
{
return true ;
}
else
{
return false;
}
}
};