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

Combine uppercase with valid #565

Closed
pon opened this issue Feb 25, 2015 · 13 comments
Closed

Combine uppercase with valid #565

pon opened this issue Feb 25, 2015 · 13 comments
Assignees
Labels
support Questions, discussions, and general support
Milestone

Comments

@pon
Copy link

pon commented Feb 25, 2015

Is it possible to use string.uppercase() prior to running through the any.valid() method?

@Marsup
Copy link
Collaborator

Marsup commented Feb 26, 2015

What difference would it make ?

@Marsup Marsup added the support Questions, discussions, and general support label Feb 26, 2015
@Marsup Marsup self-assigned this Feb 26, 2015
@pon
Copy link
Author

pon commented Feb 26, 2015

I would like Joi.string().valid('AA','BB') to be able to accept the following values: ['aa','aA', Aa', ...] without having to expand the array to cover all string cases.

@Marsup
Copy link
Collaborator

Marsup commented Feb 26, 2015

So you want Joi.string().insensitive() which already exists then.

@Marsup Marsup closed this as completed Feb 26, 2015
@pon
Copy link
Author

pon commented Feb 26, 2015

So that works for the validation piece, but I lose the functionality of the resulting value being uppercase after validation takes place. Any way to have both?

@Marsup Marsup reopened this Feb 26, 2015
@Marsup
Copy link
Collaborator

Marsup commented Feb 26, 2015

@hueniverse do you mind helping me understand that 0b4b45a ? Is it purely optimization ?

@Marsup
Copy link
Collaborator

Marsup commented Feb 27, 2015

@pon until I find a solution, a hack that works is :

Joi.string().insensitive().uppercase().concat(Joi.string().valid(['AA', 'BB', ...]))

@pon
Copy link
Author

pon commented Mar 1, 2015

@Marsup - running the code below still returns the non-uppercased value:

var Joi = require('joi');

var schema = {
  key: Joi.string().insensitive().uppercase().concat(Joi.string().valid(['AA', 'BB']))
};

Joi.validate({ key: 'aa' }, schema, function (err, value) {
  // value = { key: 'aa' }
});

@Marsup
Copy link
Collaborator

Marsup commented Mar 1, 2015

My bad, thought it was working for a moment.

@pon
Copy link
Author

pon commented Mar 1, 2015

No problem - I have a non-Joi workaround for now

@Marsup
Copy link
Collaborator

Marsup commented Mar 1, 2015

Best I can think of is this :

var schema = {
  key: Joi.string().uppercase().regex(/^AA|BB$/)
};

@KeKs0r
Copy link

KeKs0r commented Apr 26, 2015

I came across this as well, and would like to see a solution. Especially for my "lout" documentation I would prefer the combination with valid over regex.

@Marsup
Copy link
Collaborator

Marsup commented Apr 27, 2015

I'm still thinking about how to lessen the performance impact of such modification.

@rudolf
Copy link

rudolf commented Feb 10, 2016

I was also expecting Joi.string().uppercase().valid('A', 'B') to solve this use case.

As far as 0b4b45a is concerned, after reading the documentation I get the impression that using .min(2).valid(2, 3, 4) is really the problem as they contradict each other. So to truly solve this I guess joi would have to distinguish between modification rules (trim(), lowercase() etc) and validation rules. And then the assertion "Cannot define rules when valid values specified" would only be applied to the latter.

@Marsup Marsup added this to the 7.3.0 milestone Feb 10, 2016
@Marsup Marsup closed this as completed in bb66e95 Feb 11, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Jan 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
support Questions, discussions, and general support
Projects
None yet
Development

No branches or pull requests

4 participants