Validate::validate_min_string_length( object $field )

Description #

Validate if length of a string is at least as defined.

Parameters #

  • $field
    object (Required) Instance of @see AP_Field object.

Source #

File: lib/class-validate.php

	public static function validate_min_string_length( $field ) {
		$value = $field->value();

		if ( ! empty( $value ) && $field->get( 'min_length' ) ) {
			$min_length = $field->get( 'min_length', 0 );
			$value      = wp_strip_all_tags( $value );
			$value      = html_entity_decode( $value, ENT_XML1, 'UTF-8' );

			if ( mb_strlen( $value, 'utf-8' ) < $min_length ) {
				$field->add_error(
					'min-string-length',
					sprintf(
						// Translators: placeholder contain field label.
						__( 'Value provided in field %1$s must be at least %2$d characters long.', 'anspress-question-answer' ),
						$field->get( 'label' ),
						$min_length
					)
				);
			}
		}
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment