Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Built-in validator suggestion #3

Open
alolis opened this issue May 4, 2013 · 5 comments
Open

Built-in validator suggestion #3

alolis opened this issue May 4, 2013 · 5 comments
Milestone

Comments

@alolis
Copy link

alolis commented May 4, 2013

Hello!

I found myself using very often a custom validator I made in order to check all the elements in a vector if they are numeric in some cases or if they match a regex pattern in some other cases.

For example, the case where I mostly use it is when I wanna validate the a vector query parameter.

e.g www.example.com?items[]=1&items[]=2

And then inside my code i take the items and use my validator, which works just fine but i thought I could propose the implementation of a build-in vector-of validator which as options will take the currently available validators and check against them if all vector elements pass the validation.

@mylesmegyesi
Copy link
Owner

@alolis I have also written that custom validator before. I haven't put it in metis yet because of some questions around how the syntax would work. I was thinking along these lines.

; with one item validator
(defvalidator user-validator
  [:zipcodes :collection {:item-validator [:numericality {:equal-to 5 :only-integer true}]}])

; with many item validators
(defvalidator user-validator
  [:numbers :collection {:item-validator [:numericality {:less-than 5} :length {:equal-to 3} :some-custom-validator]}])

What do you think?

@alolis
Copy link
Author

alolis commented May 5, 2013

That's exactly how I implemented mine as well :) I think it's pretty straight forward and clean

@alolis
Copy link
Author

alolis commented Oct 1, 2013

Hey Myles, I was wondering if you have a fork with the collection feature somewhere; I wanted to have a look at it because it seems I use it more often lately :)

...or did it make it to core and I haven't noticed?

@mylesmegyesi
Copy link
Owner

Unfortunatley it was never added to metis. I built it into the project is was working on at the time.

@alolis
Copy link
Author

alolis commented Oct 1, 2013

Definitely a useful thing to have in metis :) If we get to vote about it it's +1 from me :p

Do you think you can share the function at least? I feel it's much more complete than what I got. If not, no problem at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants