corefwnode 3.0.2 → 3.0.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/lib/Validator.js CHANGED
@@ -1,536 +1,536 @@
1
- const ErrorCodes = require('./ErrorCodes');
2
-
3
- const ErrorControl = require('./ErrorControl.js');
4
- const GeneralHandling = require('./GeneralHandling.js');
5
-
6
- /**
7
- * module.exports = class providing functions for object validation
8
- *
9
- * @author Dario Filkovic <dfilkovi@gmail.com>
10
- *
11
- * @since 1.0
12
- *
13
- * @package CoreFw
14
- */
15
- module.exports = class Validator
16
- {
17
- /**
18
- * Check values against their object definition
19
- *
20
- * @see Object
21
- *
22
- * @author Dario Filkovic <dfilkovi@gmail.com>
23
- *
24
- * @since 1.0
25
- *
26
- * @package CoreFw
27
- * @param Array values Values to check
28
- * @param String key Value key
29
- * @param Array field Field definition
30
- * @return Array Validation array
31
- */
32
- static checkValues(values, key, field)
33
- {
34
- let maxlength = { valid: true };
35
- let maxvalue = { valid: true };
36
- let minlength = { valid: true };
37
- let minvalue = { valid: true };
38
- let type = { valid: true };
39
- const required = { valid: true };
40
-
41
- if (typeof field.maxlength !== 'undefined'
42
- && typeof values[key] !== 'undefined'
43
- && values[key] !== ''
44
- && values[key] !== null)
45
- {
46
- const val = Validator.checkMaxlength(values[key], field.maxlength, field.fieldType);
47
- if (!val)
48
- {
49
- maxlength = {
50
- valid: false,
51
- maxlength: field.maxlength,
52
- };
53
- }
54
- }
55
-
56
- if (typeof field.minlength !== 'undefined'
57
- && typeof values[key] !== 'undefined'
58
- && values[key] !== ''
59
- && values[key] !== null)
60
- {
61
- const val = Validator.checkMinlength(values[key], field.minlength, field.fieldType);
62
- if (!val)
63
- {
64
- minlength = {
65
- valid: false,
66
- minlength: field.minlength,
67
- };
68
- }
69
- }
70
-
71
- if (typeof field.maxvalue !== 'undefined'
72
- && typeof values[key] !== 'undefined'
73
- && values[key] !== ''
74
- && values[key] !== null)
75
- {
76
- const val = Validator.checkMaxValue(values[key], field.maxvalue);
77
- if (!val)
78
- {
79
- maxvalue = {
80
- valid: false,
81
- maxvalue: field.maxvalue,
82
- };
83
- }
84
- }
85
-
86
- if (typeof field.minvalue !== 'undefined'
87
- && typeof values[key] !== 'undefined'
88
- && values[key] !== ''
89
- && values[key] !== null)
90
- {
91
- const val = Validator.checkMinValue(values[key], field.minvalue);
92
- if (!val)
93
- {
94
- minvalue = {
95
- valid: false,
96
- minvalue: field.minvalue,
97
- };
98
- }
99
- }
100
-
101
- if (typeof field.fieldType !== 'undefined'
102
- && typeof values[key] !== 'undefined'
103
- && values[key] !== '' && values[key] !== null)
104
- {
105
- const val = Validator.checkType(values[key], field.fieldType);
106
- if (!val)
107
- {
108
- type = {
109
- valid: false,
110
- fieldType: field.fieldType,
111
- };
112
- }
113
- }
114
-
115
- if (typeof field.req !== 'undefined' && field.req === 1)
116
- {
117
- if (typeof values[key] === 'undefined' || values[key] === '' || values[key] == null)
118
- {
119
- required.valid = false;
120
- }
121
- }
122
-
123
- return {
124
- field: key,
125
- maxlength,
126
- maxvalue,
127
- minlength,
128
- minvalue,
129
- type,
130
- req: required,
131
- };
132
- }
133
-
134
- /**
135
- * Validate fields
136
- *
137
- * @see Object
138
- *
139
- * @author Dario Filkovic <dfilkovi@gmail.com>
140
- *
141
- * @since 1.0
142
- *
143
- * @package CoreFw
144
- * @param Array values Values to check
145
- * @param instance Pointer to object instance
146
- * @return Array Array of 'error' boolean and 'notice' messages or only 'error' boolean if no error
147
- */
148
- static async validate(values, instance)
149
- {
150
- const result = [];
151
-
152
- const nameValues = instance.tableConf();
153
- for (const key in nameValues.fields)
154
- {
155
- if (nameValues.fields[key])
156
- {
157
- const field = nameValues.fields[key];
158
- if (typeof values[key] !== 'undefined' && typeof values[key] === 'object' && values[key] !== null)
159
- {
160
- continue;
161
- }
162
- result.push(Validator.checkValues(values, key, field));
163
- }
164
- }
165
-
166
- for (const key in nameValues.id)
167
- {
168
- if (nameValues.id[key])
169
- {
170
- const field = nameValues.id[key];
171
- if (typeof values[key] !== 'undefined' && typeof values[key] === 'object' && values[key] !== null)
172
- {
173
- continue;
174
- }
175
- result.push(Validator.checkValues(values, key, field));
176
- }
177
- }
178
-
179
- const resultOut = {
180
- error: {},
181
- };
182
-
183
- for (const field in result)
184
- {
185
- if (result[field])
186
- {
187
- const value = result[field];
188
- for (const key in value)
189
- {
190
- if (value[key])
191
- {
192
- const second = value[key];
193
- if (second.valid === false)
194
- {
195
- if (resultOut.error.error === undefined)
196
- {
197
- resultOut.error = ErrorCodes.error('field_errors');
198
- }
199
- if (resultOut.error.errors === undefined)
200
- {
201
- resultOut.error.errors = [];
202
- }
203
-
204
- resultOut.error.errors.push(ErrorControl.error(result[field].field, key, second[field]));
205
- }
206
- }
207
- }
208
- }
209
- }
210
-
211
- if (resultOut.error instanceof Error)
212
- {
213
- throw (resultOut.error);
214
- }
215
- }
216
-
217
- /**
218
- * Check max length
219
- *
220
- * @author Dario Filkovic <dfilkovi@gmail.com>
221
- *
222
- * @since 1.0
223
- *
224
- * @package CoreFw
225
- * @param String value
226
- * @param int maxValue
227
- * @param String fieldType
228
- * @return boolean
229
- */
230
- static checkMaxlength(valueIn, maxValue, fieldType)
231
- {
232
- let value = valueIn;
233
- if (fieldType === 'float')
234
- {
235
- value = value.toString().replace('.', '');
236
- }
237
- if (value.length > maxValue)
238
- {
239
- return false;
240
- }
241
- return true;
242
- }
243
-
244
- /**
245
- * Check max value
246
- *
247
- * @author Dario Filkovic <dfilkovi@gmail.com>
248
- *
249
- * @since 1.0
250
- *
251
- * @package CoreFw
252
- * @param String value
253
- * @param int maxValue
254
- * @return boolean
255
- */
256
- static checkMaxValue(value, maxValue)
257
- {
258
- if (parseInt(value, 10) > maxValue)
259
- {
260
- return false;
261
- }
262
- return true;
263
- }
264
-
265
- /**
266
- * Check min length
267
- *
268
- * @author Dario Filkovic <dfilkovi@gmail.com>
269
- *
270
- * @since 1.0
271
- *
272
- * @package CoreFw
273
- * @param String value
274
- * @param int minLength
275
- * @param String fieldType
276
- * @return boolean
277
- */
278
- static checkMinlength(valueIn, minLength, fieldType)
279
- {
280
- let value = valueIn;
281
- if (fieldType === 'float')
282
- {
283
- value = value.toString().replace('.', '');
284
- }
285
- if (value.length < minLength)
286
- {
287
- return false;
288
- }
289
- return true;
290
- }
291
-
292
- /**
293
- * Check min value
294
- *
295
- * @author Dario Filkovic <dfilkovi@gmail.com>
296
- *
297
- * @since 1.0
298
- *
299
- * @package CoreFw
300
- * @param String value
301
- * @param int minValue
302
- * @return boolean
303
- */
304
- static checkMinValue(value, minValue)
305
- {
306
- if (parseInt(value, 10) < minValue)
307
- {
308
- return false;
309
- }
310
- return true;
311
- }
312
-
313
- /**
314
- * Check field type
315
- *
316
- * @author Dario Filkovic <dfilkovi@gmail.com>
317
- *
318
- * @since 1.0
319
- *
320
- * @package CoreFw
321
- * @param String value
322
- * @param String type
323
- * @return boolean
324
- */
325
- static checkType(value, type)
326
- {
327
- let res = false;
328
-
329
- switch (type)
330
- {
331
- case 'email':
332
- res = Validator.checkEmailAddress(value);
333
- break;
334
- case 'text':
335
- res = true;
336
- break;
337
- case 'string':
338
- res = true;
339
- break;
340
- case 'blob':
341
- res = true;
342
- break;
343
- case 'sc':
344
- res = Validator.checkSpecChar(value);
345
- break;
346
- case 'int':
347
- res = Validator.checkInt(value);
348
- break;
349
- case 'num':
350
- res = Validator.checkNum(value);
351
- break;
352
- case 'float':
353
- res = Validator.checkInt(value);
354
- break;
355
- case 'dateTime':
356
- res = Validator.checkDateTime(value);
357
- break;
358
- case 'date':
359
- res = Validator.checkDate(value);
360
- break;
361
- case 'time':
362
- res = Validator.checkTime(value);
363
- break;
364
- case 'file':
365
- res = Validator.checkFileName(value);
366
- break;
367
- case 'pathFile':
368
- res = Validator.checkPathFileName(value);
369
- break;
370
- case 'oib':
371
- res = Validator.checkOib(value);
372
- break;
373
- default:
374
- res = true;
375
- break;
376
- }
377
- return res;
378
- }
379
-
380
-
381
- /**
382
- * Check email
383
- * @param String email
384
- * @return boolean
385
- */
386
- static checkEmailAddress(email)
387
- {
388
- return GeneralHandling.checkEmailAddress(email);
389
- }
390
-
391
- /**
392
- * Check for valid filename
393
- * @param String value
394
- * @return boolean
395
- */
396
- static checkFileName(value)
397
- {
398
- const re = new RegExp('[^\\/]+.[^\\/]+$');
399
- return !re.test(value);
400
- }
401
-
402
- /**
403
- * Check for valid path and filename
404
- * @param String value
405
- * @return boolean
406
- */
407
- static checkPathFileName(value)
408
- {
409
- const re = new RegExp('%^[a-z0-9_-|/]+.[a-z0-9]+%i');
410
- return !re.test(value);
411
- }
412
-
413
-
414
- /**
415
- * Check for special character (username, password)
416
- * @param String value
417
- * @return boolean
418
- */
419
- static checkSpecChar(value)
420
- {
421
- const re = new RegExp('^[a-z0-9_@]+');
422
- return !re.test(value);
423
- }
424
-
425
- /**
426
- * Check if it is a int value
427
- * @param String value
428
- * @return boolean
429
- */
430
- static checkInt(value)
431
- {
432
- if (!GeneralHandling.is_numeric(value))
433
- {
434
- return false;
435
- }
436
- return true;
437
- }
438
-
439
- /**
440
- * Check if it is a num value but to post as string (leading zero)
441
- * @param String value
442
- * @return boolean
443
- */
444
- static checkNum(value)
445
- {
446
- if (!GeneralHandling.is_numeric(value))
447
- {
448
- return false;
449
- }
450
- return true;
451
- }
452
-
453
-
454
- /**
455
- * Check for if it is an required field
456
- * @param String value
457
- * @return boolean
458
- */
459
- static checkReq(value)
460
- {
461
- if (typeof value === 'undefined' || value === '')
462
- {
463
- return false;
464
- }
465
- return true;
466
- }
467
-
468
- /**
469
- * Check if it is a date time
470
- * @param String dateTime
471
- * @return boolean
472
- */
473
- static checkDateTime(dateTime)
474
- {
475
- // eslint-disable-next-line max-len
476
- const re = new RegExp('^([0-2][0-9]{3})-(0[1-9]|1[0-2])-([0-2][0-9]|3[0-1]) ([0-1][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])(.[0-9][0-9][0-9])?$');
477
- return re.test(dateTime);
478
- }
479
-
480
- /**
481
- * Check if it is a date
482
- * @param String date
483
- * @return boolean
484
- */
485
- static checkDate(date)
486
- {
487
- const re = new RegExp('^([0-2][0-9]{3})-(0[1-9]|1[0-2])-([0-2][0-9]|3[0-1])?$');
488
- return re.test(date);
489
- }
490
-
491
- /**
492
- * Check if it is a time
493
- * @param String time
494
- * @return boolean
495
- */
496
- static checkTime(time)
497
- {
498
- const re = new RegExp('^([0-1][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])( ([-+]([0-1][0-9]):00))?$');
499
- return re.test(time);
500
- }
501
-
502
- /**
503
- * Check if it is an OIB (croatian identification number)
504
- * @param String oib
505
- * @return boolean
506
- */
507
- static checkOib(oib)
508
- {
509
- if (oib.length === 11)
510
- {
511
- if (GeneralHandling.is_numeric(oib))
512
- {
513
- let a = 10;
514
- for (let i = 0; i < 10; i += 1)
515
- {
516
- a += parseInt(oib.substr(i, 1), 10);
517
- a %= 10;
518
- if (a === 0)
519
- {
520
- a = 10;
521
- }
522
- a *= 2;
523
- a %= 11;
524
- }
525
- let kontrolni = 11 - a;
526
- if (kontrolni === 10)
527
- {
528
- kontrolni = 0;
529
- }
530
- return true;
531
- }
532
- return false;
533
- }
534
- return false;
535
- }
536
- };
1
+ const ErrorCodes = require('./ErrorCodes');
2
+
3
+ const ErrorControl = require('./ErrorControl.js');
4
+ const GeneralHandling = require('./GeneralHandling.js');
5
+
6
+ /**
7
+ * module.exports = class providing functions for object validation
8
+ *
9
+ * @author Dario Filkovic <dfilkovi@gmail.com>
10
+ *
11
+ * @since 1.0
12
+ *
13
+ * @package CoreFw
14
+ */
15
+ module.exports = class Validator
16
+ {
17
+ /**
18
+ * Check values against their object definition
19
+ *
20
+ * @see Object
21
+ *
22
+ * @author Dario Filkovic <dfilkovi@gmail.com>
23
+ *
24
+ * @since 1.0
25
+ *
26
+ * @package CoreFw
27
+ * @param Array values Values to check
28
+ * @param String key Value key
29
+ * @param Array field Field definition
30
+ * @return Array Validation array
31
+ */
32
+ static checkValues(values, key, field)
33
+ {
34
+ let maxlength = { valid: true };
35
+ let maxvalue = { valid: true };
36
+ let minlength = { valid: true };
37
+ let minvalue = { valid: true };
38
+ let type = { valid: true };
39
+ const required = { valid: true };
40
+
41
+ if (typeof field.maxlength !== 'undefined'
42
+ && typeof values[key] !== 'undefined'
43
+ && values[key] !== ''
44
+ && values[key] !== null)
45
+ {
46
+ const val = Validator.checkMaxlength(values[key], field.maxlength, field.fieldType);
47
+ if (!val)
48
+ {
49
+ maxlength = {
50
+ valid: false,
51
+ maxlength: field.maxlength,
52
+ };
53
+ }
54
+ }
55
+
56
+ if (typeof field.minlength !== 'undefined'
57
+ && typeof values[key] !== 'undefined'
58
+ && values[key] !== ''
59
+ && values[key] !== null)
60
+ {
61
+ const val = Validator.checkMinlength(values[key], field.minlength, field.fieldType);
62
+ if (!val)
63
+ {
64
+ minlength = {
65
+ valid: false,
66
+ minlength: field.minlength,
67
+ };
68
+ }
69
+ }
70
+
71
+ if (typeof field.maxvalue !== 'undefined'
72
+ && typeof values[key] !== 'undefined'
73
+ && values[key] !== ''
74
+ && values[key] !== null)
75
+ {
76
+ const val = Validator.checkMaxValue(values[key], field.maxvalue);
77
+ if (!val)
78
+ {
79
+ maxvalue = {
80
+ valid: false,
81
+ maxvalue: field.maxvalue,
82
+ };
83
+ }
84
+ }
85
+
86
+ if (typeof field.minvalue !== 'undefined'
87
+ && typeof values[key] !== 'undefined'
88
+ && values[key] !== ''
89
+ && values[key] !== null)
90
+ {
91
+ const val = Validator.checkMinValue(values[key], field.minvalue);
92
+ if (!val)
93
+ {
94
+ minvalue = {
95
+ valid: false,
96
+ minvalue: field.minvalue,
97
+ };
98
+ }
99
+ }
100
+
101
+ if (typeof field.fieldType !== 'undefined'
102
+ && typeof values[key] !== 'undefined'
103
+ && values[key] !== '' && values[key] !== null)
104
+ {
105
+ const val = Validator.checkType(values[key], field.fieldType);
106
+ if (!val)
107
+ {
108
+ type = {
109
+ valid: false,
110
+ fieldType: field.fieldType,
111
+ };
112
+ }
113
+ }
114
+
115
+ if (typeof field.req !== 'undefined' && field.req === 1)
116
+ {
117
+ if (typeof values[key] === 'undefined' || values[key] === '' || values[key] == null)
118
+ {
119
+ required.valid = false;
120
+ }
121
+ }
122
+
123
+ return {
124
+ field: key,
125
+ maxlength,
126
+ maxvalue,
127
+ minlength,
128
+ minvalue,
129
+ type,
130
+ req: required,
131
+ };
132
+ }
133
+
134
+ /**
135
+ * Validate fields
136
+ *
137
+ * @see Object
138
+ *
139
+ * @author Dario Filkovic <dfilkovi@gmail.com>
140
+ *
141
+ * @since 1.0
142
+ *
143
+ * @package CoreFw
144
+ * @param Array values Values to check
145
+ * @param instance Pointer to object instance
146
+ * @return Array Array of 'error' boolean and 'notice' messages or only 'error' boolean if no error
147
+ */
148
+ static async validate(values, instance)
149
+ {
150
+ const result = [];
151
+
152
+ const nameValues = instance.tableConf();
153
+ for (const key in nameValues.fields)
154
+ {
155
+ if (nameValues.fields[key])
156
+ {
157
+ const field = nameValues.fields[key];
158
+ if (typeof values[key] !== 'undefined' && typeof values[key] === 'object' && values[key] !== null)
159
+ {
160
+ continue;
161
+ }
162
+ result.push(Validator.checkValues(values, key, field));
163
+ }
164
+ }
165
+
166
+ for (const key in nameValues.id)
167
+ {
168
+ if (nameValues.id[key])
169
+ {
170
+ const field = nameValues.id[key];
171
+ if (typeof values[key] !== 'undefined' && typeof values[key] === 'object' && values[key] !== null)
172
+ {
173
+ continue;
174
+ }
175
+ result.push(Validator.checkValues(values, key, field));
176
+ }
177
+ }
178
+
179
+ const resultOut = {
180
+ error: {},
181
+ };
182
+
183
+ for (const field in result)
184
+ {
185
+ if (result[field])
186
+ {
187
+ const value = result[field];
188
+ for (const key in value)
189
+ {
190
+ if (value[key])
191
+ {
192
+ const second = value[key];
193
+ if (second.valid === false)
194
+ {
195
+ if (resultOut.error.error === undefined)
196
+ {
197
+ resultOut.error = ErrorCodes.error('field_errors');
198
+ }
199
+ if (resultOut.error.errors === undefined)
200
+ {
201
+ resultOut.error.errors = [];
202
+ }
203
+
204
+ resultOut.error.errors.push(ErrorControl.error(result[field].field, key, second[field]));
205
+ }
206
+ }
207
+ }
208
+ }
209
+ }
210
+
211
+ if (resultOut.error instanceof Error)
212
+ {
213
+ throw (resultOut.error);
214
+ }
215
+ }
216
+
217
+ /**
218
+ * Check max length
219
+ *
220
+ * @author Dario Filkovic <dfilkovi@gmail.com>
221
+ *
222
+ * @since 1.0
223
+ *
224
+ * @package CoreFw
225
+ * @param String value
226
+ * @param int maxValue
227
+ * @param String fieldType
228
+ * @return boolean
229
+ */
230
+ static checkMaxlength(valueIn, maxValue, fieldType)
231
+ {
232
+ let value = valueIn;
233
+ if (fieldType === 'float')
234
+ {
235
+ value = value.toString().replace('.', '');
236
+ }
237
+ if (value.length > maxValue)
238
+ {
239
+ return false;
240
+ }
241
+ return true;
242
+ }
243
+
244
+ /**
245
+ * Check max value
246
+ *
247
+ * @author Dario Filkovic <dfilkovi@gmail.com>
248
+ *
249
+ * @since 1.0
250
+ *
251
+ * @package CoreFw
252
+ * @param String value
253
+ * @param int maxValue
254
+ * @return boolean
255
+ */
256
+ static checkMaxValue(value, maxValue)
257
+ {
258
+ if (parseInt(value, 10) > maxValue)
259
+ {
260
+ return false;
261
+ }
262
+ return true;
263
+ }
264
+
265
+ /**
266
+ * Check min length
267
+ *
268
+ * @author Dario Filkovic <dfilkovi@gmail.com>
269
+ *
270
+ * @since 1.0
271
+ *
272
+ * @package CoreFw
273
+ * @param String value
274
+ * @param int minLength
275
+ * @param String fieldType
276
+ * @return boolean
277
+ */
278
+ static checkMinlength(valueIn, minLength, fieldType)
279
+ {
280
+ let value = valueIn;
281
+ if (fieldType === 'float')
282
+ {
283
+ value = value.toString().replace('.', '');
284
+ }
285
+ if (value.length < minLength)
286
+ {
287
+ return false;
288
+ }
289
+ return true;
290
+ }
291
+
292
+ /**
293
+ * Check min value
294
+ *
295
+ * @author Dario Filkovic <dfilkovi@gmail.com>
296
+ *
297
+ * @since 1.0
298
+ *
299
+ * @package CoreFw
300
+ * @param String value
301
+ * @param int minValue
302
+ * @return boolean
303
+ */
304
+ static checkMinValue(value, minValue)
305
+ {
306
+ if (parseInt(value, 10) < minValue)
307
+ {
308
+ return false;
309
+ }
310
+ return true;
311
+ }
312
+
313
+ /**
314
+ * Check field type
315
+ *
316
+ * @author Dario Filkovic <dfilkovi@gmail.com>
317
+ *
318
+ * @since 1.0
319
+ *
320
+ * @package CoreFw
321
+ * @param String value
322
+ * @param String type
323
+ * @return boolean
324
+ */
325
+ static checkType(value, type)
326
+ {
327
+ let res = false;
328
+
329
+ switch (type)
330
+ {
331
+ case 'email':
332
+ res = Validator.checkEmailAddress(value);
333
+ break;
334
+ case 'text':
335
+ res = true;
336
+ break;
337
+ case 'string':
338
+ res = true;
339
+ break;
340
+ case 'blob':
341
+ res = true;
342
+ break;
343
+ case 'sc':
344
+ res = Validator.checkSpecChar(value);
345
+ break;
346
+ case 'int':
347
+ res = Validator.checkInt(value);
348
+ break;
349
+ case 'num':
350
+ res = Validator.checkNum(value);
351
+ break;
352
+ case 'float':
353
+ res = Validator.checkInt(value);
354
+ break;
355
+ case 'dateTime':
356
+ res = Validator.checkDateTime(value);
357
+ break;
358
+ case 'date':
359
+ res = Validator.checkDate(value);
360
+ break;
361
+ case 'time':
362
+ res = Validator.checkTime(value);
363
+ break;
364
+ case 'file':
365
+ res = Validator.checkFileName(value);
366
+ break;
367
+ case 'pathFile':
368
+ res = Validator.checkPathFileName(value);
369
+ break;
370
+ case 'oib':
371
+ res = Validator.checkOib(value);
372
+ break;
373
+ default:
374
+ res = true;
375
+ break;
376
+ }
377
+ return res;
378
+ }
379
+
380
+
381
+ /**
382
+ * Check email
383
+ * @param String email
384
+ * @return boolean
385
+ */
386
+ static checkEmailAddress(email)
387
+ {
388
+ return GeneralHandling.checkEmailAddress(email);
389
+ }
390
+
391
+ /**
392
+ * Check for valid filename
393
+ * @param String value
394
+ * @return boolean
395
+ */
396
+ static checkFileName(value)
397
+ {
398
+ const re = new RegExp('[^\\/]+.[^\\/]+$');
399
+ return !re.test(value);
400
+ }
401
+
402
+ /**
403
+ * Check for valid path and filename
404
+ * @param String value
405
+ * @return boolean
406
+ */
407
+ static checkPathFileName(value)
408
+ {
409
+ const re = new RegExp('%^[a-z0-9_-|/]+.[a-z0-9]+%i');
410
+ return !re.test(value);
411
+ }
412
+
413
+
414
+ /**
415
+ * Check for special character (username, password)
416
+ * @param String value
417
+ * @return boolean
418
+ */
419
+ static checkSpecChar(value)
420
+ {
421
+ const re = new RegExp('^[a-z0-9_@]+');
422
+ return !re.test(value);
423
+ }
424
+
425
+ /**
426
+ * Check if it is a int value
427
+ * @param String value
428
+ * @return boolean
429
+ */
430
+ static checkInt(value)
431
+ {
432
+ if (!GeneralHandling.is_numeric(value))
433
+ {
434
+ return false;
435
+ }
436
+ return true;
437
+ }
438
+
439
+ /**
440
+ * Check if it is a num value but to post as string (leading zero)
441
+ * @param String value
442
+ * @return boolean
443
+ */
444
+ static checkNum(value)
445
+ {
446
+ if (!GeneralHandling.is_numeric(value))
447
+ {
448
+ return false;
449
+ }
450
+ return true;
451
+ }
452
+
453
+
454
+ /**
455
+ * Check for if it is an required field
456
+ * @param String value
457
+ * @return boolean
458
+ */
459
+ static checkReq(value)
460
+ {
461
+ if (typeof value === 'undefined' || value === '')
462
+ {
463
+ return false;
464
+ }
465
+ return true;
466
+ }
467
+
468
+ /**
469
+ * Check if it is a date time
470
+ * @param String dateTime
471
+ * @return boolean
472
+ */
473
+ static checkDateTime(dateTime)
474
+ {
475
+ // eslint-disable-next-line max-len
476
+ const re = new RegExp('^([0-2][0-9]{3})-(0[1-9]|1[0-2])-([0-2][0-9]|3[0-1]) ([0-1][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])(.[0-9][0-9][0-9])?$');
477
+ return re.test(dateTime);
478
+ }
479
+
480
+ /**
481
+ * Check if it is a date
482
+ * @param String date
483
+ * @return boolean
484
+ */
485
+ static checkDate(date)
486
+ {
487
+ const re = new RegExp('^([0-2][0-9]{3})-(0[1-9]|1[0-2])-([0-2][0-9]|3[0-1])?$');
488
+ return re.test(date);
489
+ }
490
+
491
+ /**
492
+ * Check if it is a time
493
+ * @param String time
494
+ * @return boolean
495
+ */
496
+ static checkTime(time)
497
+ {
498
+ const re = new RegExp('^([0-1][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])( ([-+]([0-1][0-9]):00))?$');
499
+ return re.test(time);
500
+ }
501
+
502
+ /**
503
+ * Check if it is an OIB (croatian identification number)
504
+ * @param String oib
505
+ * @return boolean
506
+ */
507
+ static checkOib(oib)
508
+ {
509
+ if (oib.length === 11)
510
+ {
511
+ if (GeneralHandling.is_numeric(oib))
512
+ {
513
+ let a = 10;
514
+ for (let i = 0; i < 10; i += 1)
515
+ {
516
+ a += parseInt(oib.substr(i, 1), 10);
517
+ a %= 10;
518
+ if (a === 0)
519
+ {
520
+ a = 10;
521
+ }
522
+ a *= 2;
523
+ a %= 11;
524
+ }
525
+ let kontrolni = 11 - a;
526
+ if (kontrolni === 10)
527
+ {
528
+ kontrolni = 0;
529
+ }
530
+ return true;
531
+ }
532
+ return false;
533
+ }
534
+ return false;
535
+ }
536
+ };