-
Notifications
You must be signed in to change notification settings - Fork 1
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
add notBlank and notEmpty as string validators #14
base: master
Are you sure you want to change the base?
add notBlank and notEmpty as string validators #14
Conversation
I want to keep this package as lean as possible. Both of your suggestion can be done by the comments i provide. |
Hello, I might have failed to find your comments. Where are they listed? As of today, I needed to write the post parsers by hand. While this can for sure be done, blank and empty operations are common enough to be included, the same way the email validator could easily be remobed and the match validator with a email regexp could be used instead. Although you have of course full freedom to decide what stays in or what stays out, empty and blank validators are far from being a corner user case, and they are present in other libraries. It was a good exercise anyways. Feel free to accept or reject it at your disposal, but the needs are clear. Also, respect validation might not be always available for use with this package. Thanks for the great work! |
You could do the following in your app: $notBlankSchema = $schema->match('/^[\s]*$/');
$notEmptySchema = $schema->minLength(1); Best, |
As far as I understand
will parse only blank strings, which is definitely not what a NotBlancSchema should be doing. It seems though that the correct way of handling this would be
Anyways, People coming here with same questions will be tricked into something they likely don't want. I personally am going with another regex assuring that one or more characters are present and that none of them is a space like character. This fortunately works for me, but won't work for people accepting strings which can contain spaces, but which cannot be blank or empty. I still think these two patterns are common enough in the validation field to be included, but wanted to document how to follow consistently from here if they are not included. I would suggest you to write these typs on documentation, because this need is very common. |
@marlon-sousa i copied the wrong regex from your PR, it was only mean't to describe how it already could be done as similar as you suggested. $notBlankSchema = $schema->trim()->minSize(1); is much better, i agree. |
@marlon-sousa it would be great if you change your PR to update your example to the readme and drop the code changes. |
In this pr we create two validators fopr strings
Why
Because it is kit common when validating request schemas that a given field, if it exists, cannot be blank or empty.