ingeni-validation 1.2.1 → 1.2.3
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 +65 -54
- package/package.json +1 -1
package/ingeni-validation.js
CHANGED
|
@@ -108,7 +108,7 @@ async function isNullValue(...params) {
|
|
|
108
108
|
|
|
109
109
|
|
|
110
110
|
|
|
111
|
-
//
|
|
111
|
+
//Validating Boolean Value required
|
|
112
112
|
async function isValidBoolean(value){
|
|
113
113
|
if(typeof value==="boolean"){
|
|
114
114
|
return true;
|
|
@@ -116,6 +116,7 @@ async function isNullValue(...params) {
|
|
|
116
116
|
return false;
|
|
117
117
|
|
|
118
118
|
}
|
|
119
|
+
|
|
119
120
|
|
|
120
121
|
//Check Boolean Parameters
|
|
121
122
|
async function checkBooleanParams(...params) {
|
|
@@ -162,9 +163,11 @@ async function isValidMobile(mobile) {
|
|
|
162
163
|
return false;
|
|
163
164
|
}
|
|
164
165
|
|
|
165
|
-
return /^[
|
|
166
|
+
return /^[1-9]\d{9}$/.test(mobileStr);
|
|
166
167
|
}
|
|
167
168
|
|
|
169
|
+
|
|
170
|
+
|
|
168
171
|
// Email Validation
|
|
169
172
|
async function isValidEmail(email) {
|
|
170
173
|
|
|
@@ -207,6 +210,7 @@ async function isValidOtp(otp, otplength) {
|
|
|
207
210
|
|
|
208
211
|
//Valid Number or with length
|
|
209
212
|
|
|
213
|
+
|
|
210
214
|
async function isValidNumber(num, numlength = null) {
|
|
211
215
|
|
|
212
216
|
if (num === null || num === undefined || typeof num === "boolean") {
|
|
@@ -215,29 +219,22 @@ async function isValidNumber(num, numlength = null) {
|
|
|
215
219
|
|
|
216
220
|
const numStr = String(num).trim();
|
|
217
221
|
|
|
218
|
-
if (numStr === "")
|
|
219
|
-
return false;
|
|
220
|
-
}
|
|
222
|
+
if (numStr === "") return false;
|
|
221
223
|
|
|
222
|
-
//
|
|
223
|
-
if (!/^\d+$/.test(numStr))
|
|
224
|
-
return false;
|
|
225
|
-
}
|
|
224
|
+
// Only digits allowed
|
|
225
|
+
if (!/^\d+$/.test(numStr)) return false;
|
|
226
226
|
|
|
227
|
-
//
|
|
227
|
+
// Length validation (if provided)
|
|
228
228
|
if (numlength !== null) {
|
|
229
|
-
if (!Number.isInteger(numlength) || numlength <= 0)
|
|
230
|
-
return false;
|
|
231
|
-
}
|
|
229
|
+
if (!Number.isInteger(numlength) || numlength <= 0) return false;
|
|
232
230
|
|
|
233
|
-
if (numStr.length !== numlength)
|
|
234
|
-
return false;
|
|
235
|
-
}
|
|
231
|
+
if (numStr.length !== numlength) return false;
|
|
236
232
|
}
|
|
237
233
|
|
|
238
234
|
return true;
|
|
239
235
|
}
|
|
240
236
|
|
|
237
|
+
|
|
241
238
|
//Pincode validation
|
|
242
239
|
|
|
243
240
|
async function isValidPin(pinCode) {
|
|
@@ -324,15 +321,25 @@ async function isValidDate(value, format) {
|
|
|
324
321
|
|
|
325
322
|
//Validate Price
|
|
326
323
|
|
|
327
|
-
async function isValidPrice(price){
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
324
|
+
async function isValidPrice(price) {
|
|
325
|
+
if (price === null || price === undefined) return false;
|
|
326
|
+
if (typeof price === "boolean") return false;
|
|
327
|
+
|
|
328
|
+
const str = String(price).trim();
|
|
329
|
+
|
|
330
|
+
// Reject empty string
|
|
331
|
+
if (str === "") return false;
|
|
332
|
+
|
|
333
|
+
// Reject non-numeric strings like "fdsjfkjs"
|
|
334
|
+
if (!/^\d+(\.\d+)?$/.test(str)) return false;
|
|
335
|
+
|
|
336
|
+
const num = Number(str);
|
|
335
337
|
|
|
338
|
+
// Reject zero or negative
|
|
339
|
+
if (num <= 0) return false;
|
|
340
|
+
|
|
341
|
+
return true;
|
|
342
|
+
}
|
|
336
343
|
|
|
337
344
|
|
|
338
345
|
//Validate Gender
|
|
@@ -347,6 +354,40 @@ async function isValidDate(value, format) {
|
|
|
347
354
|
return ["m", "f", "male", "female", "other"].includes(val);
|
|
348
355
|
}
|
|
349
356
|
|
|
357
|
+
|
|
358
|
+
//allow this format only ("20.2849144,85.8078186")
|
|
359
|
+
|
|
360
|
+
async function isValidCoordinates(location) {
|
|
361
|
+
|
|
362
|
+
if (location === null || location === undefined) return false;
|
|
363
|
+
|
|
364
|
+
if (typeof location === "boolean") return false;
|
|
365
|
+
|
|
366
|
+
if (typeof location !== "string") return false;
|
|
367
|
+
|
|
368
|
+
if (location.length === 0) return false;
|
|
369
|
+
|
|
370
|
+
if (location.includes(" ")) return false;
|
|
371
|
+
|
|
372
|
+
const regex = /^-?\d{1,2}(\.\d+)?,-?\d{1,3}(\.\d+)?$/;
|
|
373
|
+
if (!regex.test(location)) return false;
|
|
374
|
+
|
|
375
|
+
const [latStr, lngStr] = location.split(",");
|
|
376
|
+
|
|
377
|
+
const lat = Number(latStr);
|
|
378
|
+
const lng = Number(lngStr);
|
|
379
|
+
|
|
380
|
+
// Extra safety
|
|
381
|
+
if (!Number.isFinite(lat) || !Number.isFinite(lng)) return false;
|
|
382
|
+
|
|
383
|
+
if (lat < -90 || lat > 90) return false;
|
|
384
|
+
if (lng < -180 || lng > 180) return false;
|
|
385
|
+
|
|
386
|
+
return true;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
|
|
350
391
|
|
|
351
392
|
//Stop details Validation "stop_details":[{"30":["Baripada","13:00","13:01","21.9319,86.7465"]}]
|
|
352
393
|
|
|
@@ -467,36 +508,6 @@ async function isValidStopDetails(stop_details){
|
|
|
467
508
|
|
|
468
509
|
|
|
469
510
|
|
|
470
|
-
//allow this format only ("20.2849144,85.8078186")
|
|
471
|
-
|
|
472
|
-
async function isValidCoordinates(location) {
|
|
473
|
-
|
|
474
|
-
if (location === null || location === undefined) return false;
|
|
475
|
-
|
|
476
|
-
if (typeof location === "boolean") return false;
|
|
477
|
-
|
|
478
|
-
if (typeof location !== "string") return false;
|
|
479
|
-
|
|
480
|
-
if (location.length === 0) return false;
|
|
481
|
-
|
|
482
|
-
if (location.includes(" ")) return false;
|
|
483
|
-
|
|
484
|
-
const regex = /^-?\d{1,2}(\.\d+)?,-?\d{1,3}(\.\d+)?$/;
|
|
485
|
-
if (!regex.test(location)) return false;
|
|
486
|
-
|
|
487
|
-
const [latStr, lngStr] = location.split(",");
|
|
488
|
-
|
|
489
|
-
const lat = Number(latStr);
|
|
490
|
-
const lng = Number(lngStr);
|
|
491
|
-
|
|
492
|
-
// Extra safety
|
|
493
|
-
if (!Number.isFinite(lat) || !Number.isFinite(lng)) return false;
|
|
494
|
-
|
|
495
|
-
if (lat < -90 || lat > 90) return false;
|
|
496
|
-
if (lng < -180 || lng > 180) return false;
|
|
497
|
-
|
|
498
|
-
return true;
|
|
499
|
-
}
|
|
500
511
|
|
|
501
512
|
|
|
502
513
|
|