Skip to content

Instantly share code, notes, and snippets.

@albionselimaj
Created February 4, 2018 21:40
Show Gist options
  • Save albionselimaj/effddf55a9f73463a0c979a38a39a766 to your computer and use it in GitHub Desktop.
Save albionselimaj/effddf55a9f73463a0c979a38a39a766 to your computer and use it in GitHub Desktop.
Regex validation rules
<?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