Created
April 3, 2015 20:44
-
-
Save tripflex/66f2eb890d5fc07ff324 to your computer and use it in GitHub Desktop.
Custom validation for number with decimals
This file contains 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', 'check_price_job_field'); | |
function check_price_job_field( $has_error, $fields, $values ){ | |
// Return true if this field doesn't exist (to prevent errors if you dont have field created) | |
if( ! isset( $values['job']['price'] ) ) return true; | |
if( empty( $values['job']['price'] ) || ! is_float( $values['job']['price'] ) ){ | |
throw new Exception( __( 'The custom field value must be numerical with 2 decimal places' ) ); | |
} | |
// Return true to not have any errors and allow form to continue | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment