Field Validation allowing line breaks

Hey guys,

we want to create a long text field and validate the input.

Actual we worked with this setup:

// GravityForms: Blocklist & Whitelist//
add_filter( 'gform_field_validation_84_64', 'custom_validation3', 10, 4 );
add_filter( 'gform_field_validation_84_65', 'custom_validation3', 10, 4 );


// PHP FUNKTION //
// Erlaubte Zeichen: a-z, A-Z, 0-9, ".", "_" //

function custom_validation3( $result, $value, $form, $field ) {


	if ( ! empty( $value ) && ! preg_match('/^[a-zA-Z0-9äöüÄÖÜ._]+$/', $value ) ) {
		$result['is_valid'] = false;
		$result['message'] = 'Leider ist dies keine gültige Eingabe. Pro Zeile nur einen Account, verwende bitte kein @, # oder Links.';
	}
	return $result;
}

Our problem is, we also need to allow line breaks, like shown here.

So the question now, how can we achieve this? :frowning:

Thanks for your help guys!

Hello Erik. You can match a line-break with \s as described in this comment:

Add that to your list of allowed characters and test it out.

There are other resources online that describe ways of matching a new line as well:

If you have any trouble, please let us know.

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