ingeni-validation 1.1.4 → 1.1.5
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 +35 -19
- package/package.json +1 -1
package/ingeni-validation.js
CHANGED
|
@@ -220,32 +220,48 @@ async function isValidPin(pinCode) {
|
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
|
|
223
|
-
//Valid Date Time (isValidDate(value,
|
|
224
|
-
function isValidDate(value, format) {
|
|
223
|
+
// Valid Date Time (isValidDate(value,"yyyy-mm-dd") , isValidDate(value,"yyyy-mm-dd h:i:s"))
|
|
225
224
|
|
|
226
|
-
|
|
225
|
+
function isValidDate(value, format) {
|
|
227
226
|
|
|
228
|
-
|
|
227
|
+
// Reject null, undefined
|
|
228
|
+
if (value === null || value === undefined) {
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// Reject non-string values
|
|
233
|
+
if (typeof value !== "string") {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
229
236
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
237
|
+
// Reject empty or spaces
|
|
238
|
+
if (value.trim().length === 0) {
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
let regex;
|
|
233
243
|
|
|
234
|
-
|
|
235
|
-
regex = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01]) ([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/;
|
|
236
|
-
break;
|
|
244
|
+
switch (format.toLowerCase()) {
|
|
237
245
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
246
|
+
case "yyyy-mm-dd":
|
|
247
|
+
regex = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/;
|
|
248
|
+
break;
|
|
241
249
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
250
|
+
case "yyyy-mm-dd h:i:s":
|
|
251
|
+
regex = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01]) ([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/;
|
|
252
|
+
break;
|
|
245
253
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
254
|
+
default:
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (!regex.test(value)) {
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const d = new Date(value.replace(" ", "T"));
|
|
263
|
+
return !isNaN(d.getTime());
|
|
264
|
+
}
|
|
249
265
|
|
|
250
266
|
|
|
251
267
|
|