Support

Account

Home Forums Backend Issues (wp-admin) Adding custom validation in admin fields

Helping

Adding custom validation in admin fields

  • How can I add a custom validation for the url type in the advanced custom field.
    I want to validate the input for the http:// or https://

  • Hi @mukesh.t,

    You can use parse_url(...) PHP function in your acf/validate_value function.

    add_filter('acf/validate_value/name=validate_this_image', 'my_acf_validate_value', 10, 4);
    
    function my_acf_validate_value( $valid, $value, $field, $input ){
    	
    	if( !$valid ) {
    		
    		return $valid;
    		
    	}
    	...	
    	parse_url($value);
    
    	if($url['scheme'] == 'https'){
    	   // is https;
    	}
    	...	
    	
    }
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Adding custom validation in admin fields’ is closed to new replies.