Username validation not possible

Hi there,

I try to prevent that new Users can use blanks in their username.
(and btw I think its a bug that the addon can create users with that)
It should be “JaneDoe” or “jane-doe” but NOT “Jane Doe”

I already tried this code which I found in this code here in the forum:

// form 14, field 3
add_filter( 'gform_field_validation_14_3', 'character_validation', 10, 4 );
function character_validation( $result, $value, $form, $field ) {
	
	// combine all three parts of the name field into one string for easy comparison
	$all_names = implode( $value );
	GFCommon::log_debug( __METHOD__ . '(): ALL NAMES => ' . print_r( $all_names, true ) );
	
	// Check if value contains only letters (A-Z and a-z)
	if ( ! preg_match( '/^[A-Za-z\-]+$/', $all_names ) ) {
		$result['is_valid'] = false;
		$result['message'] = 'Bitte nur Buchstaben, Zahlen und Bindestrich verwenden. Keine Leerzeichen verlaubt.';
	}

	return $result;
}

But that caused an php error :frowning:

Any other ideas?

Hello. There are no syntax errors in that code that I can see. What is the PHP error you are receiving?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.