forked from ikr/tv4-formats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (38 loc) · 1.18 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
(function () {
'use strict';
var moment = require('moment'),
validator = require('validator');
exports.date = function (value) {
if (/^[0-9]{4,}-[0-9]{2}-[0-9]{2}$/.test(value) && moment(value, 'YYYY-MM-DD').isValid()) {
return null;
}
return 'A valid date in YYYY-MM-DD format expected';
};
exports['date-time'] = function (value) {
if (
/[0-9]{4,}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(?:[+-][0-9]{2}:[0-9]{2}|Z)/.test(value) &&
moment(value).isValid()
) {
return null;
}
return 'A valid ISO 8601 date/time string expected';
};
exports.email = function (value) {
if (validator.isEmail(value)) {
return null;
}
return 'E-mail address expected';
};
exports.uri = function (value) {
if (validator.isURL(value)) {
return null;
}
return 'URI expected';
};
exports['credit-card-number'] = function (value) {
if (validator.isCreditCard(value)) {
return null;
}
return 'A valid credit card number format expected';
};
}());