Created
February 4, 2018 21:40
-
-
Save albionselimaj/effddf55a9f73463a0c979a38a39a766 to your computer and use it in GitHub Desktop.
Regex validation rules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter('submit_job_form_validate_fields', function( $isValid, $fields, $values ) { | |
foreach ( $fields['job'] as $key => $field ) { | |
// Example regex validation | |
if ( $field['slug'] == 'phone' && isset( $values['job']['phone'] ) && preg_match( "/(foo)(bar)/", $values['job']['phone'] ) ) { | |
return new \WP_Error( 'validation-error', sprintf( __( '%s isn\'t valid', 'my-listing' ), $field['label'] ) ); | |
} | |
} | |
return $isValid; | |
}, 100, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment