Created
June 26, 2019 09:14
-
-
Save Pebblo/be5b93e1912f89e8f2c1e7c66c33fcf3 to your computer and use it in GitHub Desktop.
Example of how to override the validation stratey used on a EE_Phone_Input field.
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 //Please do not include the opening PHP tag | |
add_filter('FHEE__EE_Form_Input_Base___construct__input_args', 'tw_ee_EE_Form_Input_Base___construct__input_args', 10, 2); | |
function tw_ee_EE_Form_Input_Base___construct__input_args( $input_args, $input ) { | |
if( $input instanceof EE_Phone_Input ) { | |
if( $input->has_validation_strategy('EE_Text_Validation_Strategy') ) { | |
$input->remove_validation_strategy('EE_Text_Validation_Strategy'); | |
$input->add_validation_strategy( | |
new EE_Text_Validation_Strategy( | |
__('Please enter a valid phone number. Eg 123-456-7890 or 1234567890', 'event_espresso'), | |
'~^(([\d]{15})|(^[\d]{3}-[\d]{3}-[\d]{4}))$~' | |
) | |
); | |
} | |
} | |
return $input_args; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment