Luca Reghellin
Luca Reghellin

Reputation: 8101

sailsjs: model email validation seems not to work

On a fresh sailsjs installation, I've got a test model defined like this:

module.exports = {
  attributes: {
    username:{
      type:'string'
    }
    ,email:{
      type:'string'
      ,email:true
    }
  }
};

And if I navigate to this:

http://localhost:1337/user/create?username=stratboy1&[email protected]

I get this error:

{
  "error": "E_VALIDATION",
  "status": 400,
  "summary": "1 attribute is invalid",
  "model": "User",
  "invalidAttributes": {
    "email": [
      {
        "rule": "email",
        "message": "\"email\" validation rule failed for input: '[email protected]'"
      }
    ]
  }
}

Any of you knows why?

Upvotes: 2

Views: 464

Answers (1)

galactocalypse
galactocalypse

Reputation: 1935

I've come across this earlier but don't quite remember the cause.

As a quick fix, you can substitute

email: { type: 'string', email: true }

with

email: { type: 'email' }

Upvotes: 3

Related Questions