Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // http://www.gravityhelp.com/forums/topic/number-masked-field-keeps-resetting-tablet-keyboard-to-alpha
- // change 160 here to your form ID
- add_filter('gform_validation_160', 'force_input_format');
- function force_input_format($validation_result){
- // this assumes the FHA Case # is entered in field one on your form
- // change this input_ number if it's a different field
- // try to match the first 10 characters after removing leading whitespace
- $case_number = substr(trim(rgpost('input_1')), 0, 10);
- // return a validation error if $case_number is not in the proper format, or if we needed to edit the $case_number at all before checking it.
- if (!preg_match("/\d{3}-\d{6}/", $case_number) || ($case_number != rgpost('input_1'))) {
- $validation_result['is_valid'] = false;
- foreach($validation_result['form']['fields'] as &$field){
- // field 1 is the field where we want to show the validation message
- if($field['id'] == 1){
- $field['failed_validation'] = true;
- $field['validation_message'] = 'The FHA Case Number code you entered is invalid: please check the number and try again.';
- break;
- }
- }
- }
- return $validation_result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement