ingeni-validation 1.1.3 → 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.
@@ -220,6 +220,49 @@ async function isValidPin(pinCode) {
220
220
  }
221
221
 
222
222
 
223
+ // Valid Date Time (isValidDate(value,"yyyy-mm-dd") , isValidDate(value,"yyyy-mm-dd h:i:s"))
223
224
 
225
+ function isValidDate(value, format) {
224
226
 
225
- export {validateMandate,validateOptional, isValidMobile, isValidEmail, isValidOtp, isValidPin,isValidNumber,isValidBoolean,checkBooleanParams};
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
+ }
236
+
237
+ // Reject empty or spaces
238
+ if (value.trim().length === 0) {
239
+ return false;
240
+ }
241
+
242
+ let regex;
243
+
244
+ switch (format.toLowerCase()) {
245
+
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;
249
+
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;
253
+
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
+ }
265
+
266
+
267
+
268
+ export {validateMandate,validateOptional, isValidMobile, isValidEmail, isValidOtp, isValidPin,isValidNumber,isValidBoolean,checkBooleanParams,isValidDate};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ingeni-validation",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "Ingeni Validation",
5
5
  "license": "ISC",
6
6
  "author": "",