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

More readable errors for patterns #78

Open
o0Djeen0o opened this issue May 19, 2020 · 1 comment
Open

More readable errors for patterns #78

o0Djeen0o opened this issue May 19, 2020 · 1 comment

Comments

@o0Djeen0o
Copy link

Hi,

I'm struggling with patterns usage and proper error display.

I would like to validate a range of number values, something like 1024-2048, and I have a pattern to express allowed number values (values between 1024 and 49151) :
pattern: "^(102[4-9]|10[3-9][0-9]|1[1-9][0-9]{2}|[2-9][0-9]{3}|[1-3][0-9]{4}|4[0-8][0-9]{3}|490[0-9]{2}|491[0-4][0-9]|4915[01])-(102[4-9]|10[3-9][0-9]|1[1-9][0-9]{2}|[2-9][0-9]{3}|[1-3][0-9]{4}|4[0-8][0-9]{3}|490[0-9]{2}|491[0-4][0-9]|4915[01])$"

But the output for user is displayed as:

07:43:09.693Z - error: PATTERN should match pattern "^(102[4-9]|10[3-9][0-9]|1[1-9][0-9]{2}|[2-9][0-9]{3}|[1-3][0-9]{4}|4[0-8][0-9]{3}|490[0-9]{2}|491[0-4][0-9]|4915[01])-(102[4-9]|10[3-9][0-9]|1[1-9][0-9]{2}|[2-9][0-9]{3}|[1-3][0-9]{4}|4[0-8][0-9]{3}|490[0-9]{2}|491[0-4][0-9]|4915[01])$"
> 4 |   "ports": "3000-302"

which is valid, but not readable to understand what is a valid input.

I would like to know if there is a way to force a message when an error occurs, for instance to use a description instead of the pattern value, or if any other mechanism exists to provide a more readable output without the need to put logic from error report ?

Thanks for your help !

@megamorf
Copy link

Why use a regex when you can define a number with lower and upper boundaries?

orgads pushed a commit to orgads/better-ajv-errors that referenced this issue Dec 3, 2023
chore(deps): update dependency husky to v8
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