• Resolved VB 416

    (@vinodbilagi416)


    Hello Team,
    How to validate the Name field, it’s accepting alphabet only, not numbers and special character

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi @vinodbilagi416

    I hope you are doing good today.

    Could you be more clear about what is your main goal? Name filed allows using numbers and special characters.

    Kind Regards,
    Kris

    Thread Starter VB 416

    (@vinodbilagi416)

    Hello Kris,
    Thank you for your quick response, I need to provide the users to enter their names only in the alphabet[a-z, A-Z], it will not accept the numbers[0-9].

    Thank you,

    Plugin Support Dimitris – WPMU DEV Support

    (@wpmudev-support6)

    Hello @vinodbilagi416

    As this isn’t possible out of the box, I forwarded it to our developers in case there’s any filter/workaround that we can share with you here. Your patience is highly appreciated! ??

    Thank you,
    Dimitris

    Plugin Support Dimitris – WPMU DEV Support

    (@wpmudev-support6)

    Hello @vinodbilagi416

    Please use the following code in a MU plugin which should do the trick for you.
    How to: https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    <?php
    add_filter(
    	'forminator_custom_form_submit_errors',
    	function( $submit_errors, $form_id, $field_data_array ) {
    		$field_name = 'name-1';
    		$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
    );

    Keep in mind to change the name field ID, if not the same with your form, here:
    $field_name = 'name-1';

    Take care,
    Dimitris

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Name field validation’ is closed to new replies.