• Resolved vjdoon

    (@vjdoon)


    Is there any option to validate the form field for text input. For eg if someone inputs name as John then it should accept it but if they enter John#@ then it should give an error

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @vjdoon,

    Hope this message finds you well.

    <?php
    add_filter(
    	'forminator_custom_form_submit_errors',
    	function( $submit_errors, $form_id, $field_data_array ) {               
    		$field_name = 'name-1'; //change the field name here
    		$submitted_fields = wp_list_pluck( $field_data_array, 'value', 'name' );
    
    		if( !preg_match( '/^[a-z]+$/i', $submitted_fields[ $field_name ] ) ) {
    			$submit_errors[][ $field_name ] = __( 'There is something wrong ' );
    		}
    
    		return $submit_errors;
    	},
    	10, 
    	3
    );

    This is a mu-plugin that will allow only alphabet characters, not numbers or special chars. You will find a guide about how to install a mu-plugin on this link.

    Let us know if you require additional assistance.

    Best regards,
    Laura

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hi @vjdoon ,

    I believe the code shared by Laura worked for you as you haven’t gotten back to us with additional questions.
    Hence, I will resolve this topic.

    kind regards,
    Kasia

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘special character validation on form submit’ is closed to new replies.