React.js:如何在验证器库中使用isLength?

I'm using validator library for my password validation

我正在尝试使用每个验证器进行自定义使用

However, I'm having problem when using isLength validator to see if max length is invalid

validator.isLength(e.target.value [, options])

e.target.value is my string from the Textfield

According to the documentation, options is an object which defaults to {min:0, max: undefined}. Note: this function takes into account surrogate pairs.

如何使用该语法声明最大可能的长度?

validator.isLength(e.target.value [0, 5]) is not working

我应该先创建一个对象吗?使用{“ min”:“ 0”,“ max”:“ 5”}

评论
  • dut
    dut 回复

    是的,按照文档,它应该看起来像这样

    validator.isLength(e.target.value , {min:0, max: 5})