So I want to disable special characters cause a 3rd party integration do not accept the special characters.
I have found this code below, but it also doesn’t allow space. So how do I edit the code below, so it allows spaces but just not special characters like ÆÅØ and so on.
add_filter( 'gform_field_validation', function( $result, $value, $form, $field ) {
if ( strpos( $field->cssClass, 'require_alpha_num' ) !== false && ! ctype_alnum( $value ) ) {
$result['is_valid'] = false;
$result['message'] = 'Error: You are not allowed to use special characters';
}
return $result;
}, 10, 4 );
Note - I changed the CSS Class name to “letters_spaces” as well. Be sure you add that CSS Class name to the settings on the Appearance tab of the field you want to target with this validation.