【问题标题】:How can i compare two strings for same value using joi library如何使用 joi 库比较两个字符串的相同值
【发布时间】:2020-10-22 22:14:10
【问题描述】:

我已经编写了忘记密码的代码,然后我想验证密码并使用 joi 库重新输入相同的密码。我怎样才能做到这一点。 我已经写了这段代码,但它抛出错误 joi.string.valid is not a function。

这里我使用 joi 库作为

 const schema=joi.object({
  pass:joi.string().required().label('Please Fill Password'),
 password:joi.string().min(8).required().label('Password must be 8 characters long'),
  pass2:joi.string().required().label('Please Re-enter Password'),

  password2:joi.string.valid(joi.ref('password')).label('passwords don\'t match'),

  })
  let result=schema.validate({pass:pass,password:pass,pass2:pass2,password2:pass2});
  if(result.error){
      console.log('fd'+result.error);
      response.send(result.error.details[0].context.label);    
  }
   

【问题讨论】:

    标签: node.js joi


    【解决方案1】:

    您的代码中有错字。你忘记了() 上的string() 属性password2

    // missing ()
    password2:joi.string.valid(joi.ref('password')).label('passwords don\'t match')
    // added () 
    password2:joi.string().valid(joi.ref('password')).label('passwords don\'t match')
    

    【讨论】:

      猜你喜欢
      • 2021-01-01
      • 1970-01-01
      • 2013-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多