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

Fixing a bug that will allow a value of '0' to bypass validation. #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gravityforms-regex-validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function ToggleInputRegEx(isInit){
// validate submitted data against provided regex
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)) {

$regex = '/' . $field['regexPattern'] . '/';
if (preg_match($regex, $value) !== 1) {
$result['is_valid'] = false;
Expand Down