node.js - Mongoose validation: required : false, validate : regex, issues with empty values -


I get this message with validity:

'value` `

< P> This should not be done because the phone is not required.

This is my model schema:

  var user = new schema ({_id: {type: string, required: true}, name: {type: string, required : True}, phone: {type: string, required: wrong, valid: / ^ \ d {10} $ /}, password: {type: string}, added: {type: date, default: date.nuh} ,}, {Archive: 'user'});  

It seems that when I use expected: false and set a valid property, verification of the mouth fails. If I change it in:

  Phone: {type: string, required: wrong},  

Everything is fine, why is it so? What am i doing wrong

You can try with a custom verifier because these are only triggered when it is A value on the given key, because the main selection for custom verification path () :

  var user = new schema ( {// ... Phone: {type: string}, // default to use - required: incorrect // ...}); // validate validation user.path ('phone') (function (value) {// your verification code is here, bool should be returned, 'some error message'); Take a look at this question: 

This will also effectively prevent the document to be retained in DB if the verification fails, when So that you do not handle that error. / P>

Bonus tip: Try to reach custom assumptions in a simplified way, for example, try to avoid loops when possible And in the port like the library or for the underscores in my experience I have seen that having a lot of transactions can cost them a significant expenditure.


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -