Skip to content
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