Last change
on this file since 493 was
493,
checked in by hendrikvanantwerpen, 11 years ago
|
- _ComplexValueMixin propagates priorityChange to children.
- Deserialize updated docs after save too.
- Validate to false if definitions are missing.
|
File size:
941 bytes
|
Line | |
---|
1 | var tv4 = require('tv4'); |
---|
2 | |
---|
3 | // from: http://www.w3.org/TR/html5/forms.html#valid-e-mail-address |
---|
4 | var html5EmailRe = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/; |
---|
5 | var datetimeRe = /^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z/; |
---|
6 | |
---|
7 | tv4.addFormat({ |
---|
8 | email: function(data){ |
---|
9 | if ( typeof data === "string" && html5EmailRe.test(data) ) { |
---|
10 | return null; |
---|
11 | } else { |
---|
12 | return "Probably an invalid email address."; |
---|
13 | } |
---|
14 | }, |
---|
15 | datetime: function(data){ |
---|
16 | if ( typeof data === "string" && datetimeRe.test(data) ) { |
---|
17 | return null; |
---|
18 | } else { |
---|
19 | return "Invalid timestamp."; |
---|
20 | } |
---|
21 | } |
---|
22 | }); |
---|
23 | |
---|
24 | module.exports = function() { |
---|
25 | var result = tv4.validateResult.apply(tv4,arguments); |
---|
26 | if ( result.missing.length > 0 ) { |
---|
27 | result.valid = false; |
---|
28 | } |
---|
29 | return result; |
---|
30 | }; |
---|
Note: See
TracBrowser
for help on using the repository browser.