empty strings vs non empty ones
This commit is contained in:
parent
6e457e54ff
commit
6f6ff22ec1
|
@ -117,7 +117,7 @@ schema with embedded schemas for object and array types
|
|||
|
||||
built in types
|
||||
|
||||
[string, alpha, alphanum, email, object, array, date, number, int, boolean, url, zipcode]
|
||||
[string+, string (empty string allowed), alpha, alphanum, email, object, array, date, number, int, boolean, url, zipcode]
|
||||
|
||||
to extend, add a function onto schema.types that accepts a value and returns a boolean if the type matches
|
||||
test is run AFTER schema.filters are run
|
||||
|
|
11
lib/rules.js
11
lib/rules.js
|
@ -51,7 +51,7 @@ Rules.prototype.apply = function(value)
|
|||
throw this.Error("%p is a required parameter", "required", value);
|
||||
}
|
||||
}
|
||||
// if value is nore required and is undefined, no more rules need to be run
|
||||
// if value is not required and is undefined, no more rules need to be run
|
||||
else if(_.isUndefined(value))
|
||||
return value;
|
||||
|
||||
|
@ -200,11 +200,16 @@ var checks =
|
|||
|
||||
var is =
|
||||
{
|
||||
'string': function(value)
|
||||
'string+': function(value)
|
||||
{
|
||||
return typeof(value) == 'string' && value !== "";
|
||||
},
|
||||
|
||||
'string': function(value)
|
||||
{
|
||||
return typeof(value) == 'string';
|
||||
},
|
||||
|
||||
'alphanum': function(value)
|
||||
{
|
||||
return (/^[a-z0-9]+$/i).test(value);
|
||||
|
@ -262,7 +267,7 @@ var is =
|
|||
|
||||
'zipcode': function(value)
|
||||
{
|
||||
return (/d+\{5\}/).test(value);
|
||||
return (/\d{5}/).test(value);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Reference in New Issue