ansman/validate.js

Why is Dot (.) not allowed in the value string for name?

Closed this issue · 5 comments

name="myInput[0].text1"

The above is the format we want to achieve but not sure why are you not allowing dot in the string, as a result, the validation gets incorrect. Are there any limitations? If yes do let me know.

note: we don't want to evaluate anything. That format is to map elements properly according to the data coming.

I just went through the documentation this is because it supports nested validation.

But the users who want to use nested validation and have dot in their name string, the validation fails for them.

So I would suggest having an option to enable/disable the nested validation feature.

You can simply escape dots using a backslash before: foo\.bar

You can simply escape dots using a backslash before: foo\.bar

I appreciate your response but i don't want to that. We want the name with the dot notation. That's a requirement.

And you still can, you only need to escape while validating:

const data = {
  "foo.bar": "hello"
}
const constraints = {
  "foo\.bar": {
    presence: true
  }
}

I have the same problem with the lasest version (0.13.1), but for me the escape charater doesn't help either:
https://codepen.io/levipadre/pen/mdOqLBy?editors=0010
With \. only validate presence and ignore other validation, like email:true. I tried with \\. and in this case does nothing.
What am I doing wrong?