geraintluff / tv4

Tiny Validator for JSON Schema v4
http://geraintluff.github.io/tv4/
Other
1.17k stars 184 forks source link

email validation #102

Open ghost opened 10 years ago

ghost commented 10 years ago

Hi,

I try to validate a JSON that contains an email, so in my schema I've specified a property with email format, but I always get true even if there is no email.

Any idea ?

Thanks.

console.log(req.body);
console.log(createAccountSchema);
var isValid = tv4.validate(req.body, createAccountSchema);
console.log(isValid);
{
    "email": "something",
    "password": "password"
}
{
    "title": "Create Account Schema",
    "type": "object",
    "properties": {
        "email": {
            "type": "string",
            "format": "email"
        },
        "password": {
            "type": "string"
        }
    },
    "required": ["email", "password"]
}
true
Bartvds commented 10 years ago

Currently the common format's like email are not bundled so the value format is ignored.

There is a proposal from another user to add the basic formats the spec says should be available in validators that support the format field, like email. See https://github.com/geraintluff/tv4/issues/100