You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+52-6Lines changed: 52 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -56,13 +56,17 @@ Validators are just functions. It will be executed for each property, and return
56
56
-[Custom function](#custom-function)
57
57
-[Date](#date)
58
58
-[Model](#model)
59
+
-[Email](#email)
60
+
-[Regex](#regex)
59
61
60
62
## Type
61
63
If the data has not the specifed type, validation will fail, and that field will not be added to final validated data.
62
64
65
+
It uses typeof, so arrays will be considered valid objects. Also, there is a type "array", wich ensures data is an array.
66
+
63
67
```javascript
64
68
{
65
-
type:String// Check if data has a JS type (uses typeof)
69
+
type:String// Check if data has a JS type
66
70
}
67
71
```
68
72
@@ -118,7 +122,7 @@ Check if data is a JavaScript Date. Just need to set a boolean `date` parameter,
118
122
119
123
```javascript
120
124
{
121
-
data:Boolean// Check if data is a JS Date
125
+
date:Boolean// Check if data is a JS Date
122
126
}
123
127
```
124
128
> _Remember that JavaScript dates has type `Object`_
@@ -168,6 +172,48 @@ var batman = geopoint.modelate(myGeopoint);
168
172
console.log(batman);
169
173
```
170
174
175
+
## Email
176
+
Check if data is an email. Might be just a boolean, or an object to check domains:
177
+
178
+
```javascript
179
+
{
180
+
email:Boolean// Check if data is an email
181
+
}
182
+
```
183
+
184
+
Also, to check domains:
185
+
```javascript
186
+
{
187
+
email: {
188
+
domain:'gmail.com'
189
+
}
190
+
}
191
+
```
192
+
193
+
Or, to enable more than one valid domains:
194
+
```javascript
195
+
{
196
+
email: {
197
+
domain: ['gmail.com', 'google.com']
198
+
}
199
+
}
200
+
```
201
+
202
+
## Regex
203
+
Test a regular expression over the data.
204
+
```javascript
205
+
{
206
+
regex: Regex // Check if data is regex valid
207
+
}
208
+
```
209
+
An example might be:
210
+
```javascript
211
+
{
212
+
regex:/[a]/
213
+
}
214
+
```
215
+
This will validate `asd` but not `sdf`
216
+
171
217
# Tests
172
218
173
219
I'm currently adding tests to this code. I'm using Jasmine, and saving tests in `/spec` folder.
@@ -195,10 +241,10 @@ Master version might not have the last test updates. Check out the `develop` bra
195
241
- [ ] Validators
196
242
- [x] Type
197
243
- [x] Length
198
-
- [] Value
199
-
- [] Custom function
200
-
- [] Date
201
-
- [ ] Model
244
+
- [x] Value
245
+
- [x] Custom function
246
+
- [x] Date
247
+
- [ ] Model (Need help with this #15)
202
248
203
249
# Contribute
204
250
You can use this code as you like. If you find a bug, or want to ask for a feature, just open an issue, and we'll do our best. If you can fix it, do a pull request to dev branch, and we promise to review it as fast as possible to merge it.
0 commit comments