LearnBoost/mongoose — pull request #753 by ManInTheBox (2012-02-28 17:44:48+00:00)
Title: Custom (user-friendly) ValidatorError message

Related to https://github.com/LearnBoost/mongoose/issues/747

Validators now accepts custom error message or if not provided, built-in error message will be used.
Error messages are borrowed from Yii PHP Framework and are stored in `errormessages.json`.

```javascript
var UserSchema = new Schema({
name: {
first: {
type: String,
required: [ true, 'Field {path} is required.' ]
},
last: {
type: String,
max: [ 30, '{path|Your dear last name} is limited to {max} characters.' ]
}
},
age: {
type: Number,
max: 100,
min: [ 5, 'Minimum value for {path|Your age} is {min}.' ]
}
});
```
This will be translated as:

* Name First is required
* Your dear last name is limited to 30 characters.
* Age is too big (maximum is 100).
* Minimum value for Your age is 5.

Also, `CastError` is improved with built-in cast error message like:
`Age must be a number.`

I added three new String validators, `min`, `max` and `length`, because I think these are common.