ingeni-validation 1.0.8 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ingeni-validation.js +33 -8
- package/package.json +1 -1
package/ingeni-validation.js
CHANGED
|
@@ -80,15 +80,34 @@ const optionMissingFields = optionalFields.filter(
|
|
|
80
80
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
//Check Boolean Parameters
|
|
84
|
+
async function checkBooleanParams(...params) {
|
|
85
|
+
for (let param of params) {
|
|
86
|
+
if (param === "true" || param === "false") {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
//Mobile No. Validation
|
|
84
95
|
async function isValidMobile(mobile) {
|
|
85
|
-
|
|
96
|
+
|
|
97
|
+
if (typeof mobile === "boolean" || mobile===null || mobile===undefined) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
|
|
86
101
|
const mobileStr = String(mobile).trim();
|
|
102
|
+
|
|
87
103
|
return /^[0-9]{10}$/.test(mobileStr);
|
|
88
104
|
}
|
|
89
105
|
|
|
90
106
|
|
|
91
107
|
async function isValidEmail(email) {
|
|
108
|
+
if (typeof email === "boolean" || email===null || email===undefined) {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
92
111
|
|
|
93
112
|
const emailStr = String(email).trim();
|
|
94
113
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
@@ -101,8 +120,10 @@ async function isValidEmail(email) {
|
|
|
101
120
|
|
|
102
121
|
|
|
103
122
|
async function isValidOtp(otp, otplength) {
|
|
104
|
-
|
|
105
|
-
|
|
123
|
+
if (typeof otp === "boolean" || otp===null || otp===undefined) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
|
|
106
127
|
if (!Number.isInteger(otplength) || otplength <= 0) return false;
|
|
107
128
|
//console.log("OTPSTR:", otpStr, otpStr.length);
|
|
108
129
|
const otpStr = String(otp).trim();
|
|
@@ -111,7 +132,10 @@ async function isValidOtp(otp, otplength) {
|
|
|
111
132
|
}
|
|
112
133
|
|
|
113
134
|
async function isValidNumber(num, numlength) {
|
|
114
|
-
|
|
135
|
+
|
|
136
|
+
if (typeof num === "boolean" || num===null || num===undefined) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
115
139
|
|
|
116
140
|
if (!Number.isInteger(numlength) || numlength <= 0) return false;
|
|
117
141
|
|
|
@@ -120,8 +144,9 @@ async function isValidNumber(num, numlength) {
|
|
|
120
144
|
}
|
|
121
145
|
|
|
122
146
|
async function isValidPin(pinCode) {
|
|
123
|
-
if (pinCode ===
|
|
124
|
-
|
|
147
|
+
if (typeof pinCode === "boolean" || pinCode===null || pinCode===undefined) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
125
150
|
// convert safely to string
|
|
126
151
|
const pinCodeStr = String(pinCode).trim();
|
|
127
152
|
|
|
@@ -131,4 +156,4 @@ async function isValidPin(pinCode) {
|
|
|
131
156
|
return /^[0-9]{6}$/.test(pinCodeStr);
|
|
132
157
|
}
|
|
133
158
|
|
|
134
|
-
export {validateMandate,validateOptional, isValidMobile, isValidEmail, isValidOtp, isValidPin,isValidNumber,isValidBoolean};
|
|
159
|
+
export {validateMandate,validateOptional, isValidMobile, isValidEmail, isValidOtp, isValidPin,isValidNumber,isValidBoolean,checkBooleanParams};
|