|
311 | 311 | } |
312 | 312 | }, |
313 | 313 |
|
314 | | - isEmpty: function(value) { |
| 314 | + isEmpty: function(value, treatWhitespaceAsEmpty) { |
315 | 315 | var attr; |
316 | 316 |
|
| 317 | + if (treatWhitespaceAsEmpty === undefined) { |
| 318 | + treatWhitespaceAsEmpty = true; |
| 319 | + } |
| 320 | + |
317 | 321 | // Null and undefined are empty |
318 | 322 | if (!v.isDefined(value)) { |
319 | 323 | return true; |
|
326 | 330 |
|
327 | 331 | // Whitespace only strings are empty |
328 | 332 | if (v.isString(value)) { |
329 | | - return v.EMPTY_STRING_REGEXP.test(value); |
| 333 | + if (treatWhitespaceAsEmpty) { |
| 334 | + return v.EMPTY_STRING_REGEXP.test(value); |
| 335 | + } |
| 336 | + |
| 337 | + return value === ""; |
330 | 338 | } |
331 | 339 |
|
332 | 340 | // For arrays we use the length property |
|
766 | 774 | }, |
767 | 775 | length: function(value, options, attribute) { |
768 | 776 | // Empty values are allowed |
769 | | - if (!v.isDefined(value)) { |
| 777 | + if (v.isEmpty(value, false)) { |
770 | 778 | return; |
771 | 779 | } |
772 | 780 |
|
|
814 | 822 | }, |
815 | 823 | numericality: function(value, options) { |
816 | 824 | // Empty values are fine |
817 | | - if (!v.isDefined(value)) { |
| 825 | + if (v.isEmpty(value, false)) { |
818 | 826 | return; |
819 | 827 | } |
820 | 828 |
|
|
915 | 923 | } |
916 | 924 |
|
917 | 925 | // Empty values are fine |
918 | | - if (!v.isDefined(value)) { |
| 926 | + if (v.isEmpty(value, false)) { |
919 | 927 | return; |
920 | 928 | } |
921 | 929 |
|
|
985 | 993 | , match; |
986 | 994 |
|
987 | 995 | // Empty values are allowed |
988 | | - if (!v.isDefined(value)) { |
| 996 | + if (v.isEmpty(value, false)) { |
989 | 997 | return; |
990 | 998 | } |
991 | 999 | if (!v.isString(value)) { |
|
1002 | 1010 | }, |
1003 | 1011 | inclusion: function(value, options) { |
1004 | 1012 | // Empty values are fine |
1005 | | - if (!v.isDefined(value)) { |
| 1013 | + if (v.isEmpty(value, false)) { |
1006 | 1014 | return; |
1007 | 1015 | } |
1008 | 1016 | if (v.isArray(options)) { |
|
1019 | 1027 | }, |
1020 | 1028 | exclusion: function(value, options) { |
1021 | 1029 | // Empty values are fine |
1022 | | - if (!v.isDefined(value)) { |
| 1030 | + if (v.isEmpty(value, false)) { |
1023 | 1031 | return; |
1024 | 1032 | } |
1025 | 1033 | if (v.isArray(options)) { |
|
1036 | 1044 | options = v.extend({}, this.options, options); |
1037 | 1045 | var message = options.message || this.message || "is not a valid email"; |
1038 | 1046 | // Empty values are fine |
1039 | | - if (!v.isDefined(value)) { |
| 1047 | + if (v.isEmpty(value, false)) { |
1040 | 1048 | return; |
1041 | 1049 | } |
1042 | 1050 | if (!v.isString(value)) { |
|
1078 | 1086 | // A URL validator that is used to validate URLs with the ability to |
1079 | 1087 | // restrict schemes and some domains. |
1080 | 1088 | url: function(value, options) { |
1081 | | - if (!v.isDefined(value)) { |
| 1089 | + if (v.isEmpty(value, false)) { |
1082 | 1090 | return; |
1083 | 1091 | } |
1084 | 1092 |
|
|
0 commit comments