Skip to content

Conversation

leadoux
Copy link

@leadoux leadoux commented Nov 25, 2020

Hi Matt.
We use your gravityforms-regex-validation plugin - thanks.
I have found a small bug where a value of 0 will not pass as True for !empty($value), and then regex validation does not happen, allowing '0' to pass strait past the regex - obviously not a desireable outcome.
Please reveiw my simple fix and consider rolling it into your code to fix this issue for all.
Regards...Adam.

public function validate($result, $value, $form, $field) {
// if validation has passed so far, and regex validation is enabled, and a pattern was provided, and a value was provided
if ($result['is_valid'] && $field['regexValidation'] && !empty($field['regexPattern']) && !empty($value)) {
if ($result['is_valid'] && $field['regexValidation'] && !empty($field['regexPattern']) && ( strlen($value) != 0 )) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion @leadoux! This is a little cleaner, and should work as well--look good to you?

Suggested change
if ($result['is_valid'] && $field['regexValidation'] && !empty($field['regexPattern']) && ( strlen($value) != 0 )) {
if ($result['is_valid'] && $field['regexValidation'] && !empty($field['regexPattern']) && strlen($value)) {

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

Successfully merging this pull request may close these issues.

2 participants