leepowelldev / mongoose-validator

Validators for mongoose models utilising validator.js
MIT License
378 stars 43 forks source link

isEmail? #8

Closed daslicht closed 11 years ago

daslicht commented 11 years ago

Hello, I tried to ass the isEmail validation like this: var emailValidator = [validate({message: "This is not an eMail"}), validate('isEmail')];

What is the correct Syntax ?

Cheers Marc

leepowelldev commented 11 years ago

Hi Marc - try: validate({ message: 'This is not an eMail' }, 'isEmail' })

daslicht commented 11 years ago

Thanks that works ! Is there also a convenient way to check if a user already exists , unique ?

On 17.08.2013, at 13:09, leepowellcouk notifications@github.com wrote:

Hi Marc - try: validate({ message: 'This is not an eMail' }, 'isEmail' })

— Reply to this email directly or view it on GitHub.

daslicht commented 11 years ago

I found this here: https://npmjs.org/package/mongoose-unique-validator But I don't see how to change the default Error Message :/ Cheers Marc

On 17.08.2013, at 13:09, leepowellcouk notifications@github.com wrote:

Hi Marc - try: validate({ message: 'This is not an eMail' }, 'isEmail' })

— Reply to this email directly or view it on GitHub.

leepowelldev commented 11 years ago

It doesn't look like you can set the error message in that plugin. You could either contact the author and ask him if he has plans to provide that functionality, or fork the repository, add it yourself and offer a pull request.

daslicht commented 11 years ago

Thanks I am on it :)

How do you solve such things ?

leepowelldev commented 11 years ago

Sole?

daslicht commented 11 years ago

"solve" sorry :) [fixed]

leepowelldev commented 11 years ago

Essentially that plugin is a wrapper around a query to the database to see if the unique item has already been used - this allows for the model to report an error at the validation level rather than at the save level (which is where mongoose does it for it's 'unique' property on a path).