forked from perscrew/react-native-form-validator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefaultRules.js
More file actions
33 lines (30 loc) · 868 Bytes
/
defaultRules.js
File metadata and controls
33 lines (30 loc) · 868 Bytes
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
'use strict';
import moment from 'moment';
// Custom default rules to validate form fields
const defaultRules = {
numbers: /^(([0-9]*)|(([0-9]*)\.([0-9]*)))$/,
email: /^(\w)+(\.\w+)*@(\w)+((\.\w{2,3}){1,3})$/,
required: /\S+/,
date(format="YYYY-MM-DD", value) {
const d = moment(value, format);
if(d == null || !d.isValid()) return false;
return true;
},
minlength(length, value) {
if (length === void(0)) {
throw 'ERROR: It is not a valid length, checkout your minlength settings.';
} else if(value.length > length) {
return true;
}
return false;
},
maxlength(length, value) {
if (length === void(0)) {
throw 'ERROR: It is not a valid length, checkout your maxlength settings.';
} else if (value.length > length) {
return false;
}
return true;
}
};
export default defaultRules;