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

Check if value is a RegEx #408

Closed
donaldpipowitch opened this issue Aug 26, 2014 · 7 comments · Fixed by #481
Closed

Check if value is a RegEx #408

donaldpipowitch opened this issue Aug 26, 2014 · 7 comments · Fixed by #481
Labels
feature New functionality or improvement
Milestone

Comments

@donaldpipowitch
Copy link

What is the correct way to check if a value is a RegEx? With an API like Joi.string(), Joi.object(), Joi.array() I thought something like Joi.regex() would be available, but this isn't the case. I couldn't find something in the docs about this.

@gaastonsr
Copy link
Contributor

It would be a nice addition.

@hueniverse
Copy link
Contributor

We can add a rule for checking obj.constructor.toString(). Something like joi.object().type('RegExp'). Would that work?

@donaldpipowitch
Copy link
Author

Sounds good! Maybe Joi.regex() could alias to Joi.object().type('RegExp') as it is a JS-native object just like Date and I would expect the API to support these in this way.

@hueniverse
Copy link
Contributor

@donaldpipowitch nah. No need for shortcuts on that one. Be explicit.

I'll take a pull request adding this.

@donaldpipowitch
Copy link
Author

You decide, that's okay for me. I would still recommend it for consistency. Why would there be an API like Joi.date(); but not Joi.regex()? I think this would be confusing for someone who sees the API for the first time.

@hueniverse
Copy link
Contributor

Because dates are very common in data schema while regex is really only applicable for JS objects. Validating that something is a regex is just not that useful use case.

jagoda added a commit to jagoda/joi that referenced this issue Nov 11, 2014
jagoda added a commit to jagoda/joi that referenced this issue Nov 11, 2014
jagoda added a commit to jagoda/joi that referenced this issue Nov 11, 2014
jagoda added a commit to jagoda/joi that referenced this issue Nov 11, 2014
jagoda added a commit to jagoda/joi that referenced this issue Nov 11, 2014
@Marsup Marsup self-assigned this Nov 11, 2014
@Marsup Marsup added this to the 4.9.0 milestone Nov 11, 2014
@hueniverse hueniverse added feature New functionality or improvement and removed request labels Sep 19, 2019
@lock
Copy link

lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New functionality or improvement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants