Validate::validate_min_string_length( object $field )
Description #
Validate if length of a string is at least as defined.
Parameters #
- $fieldobject (Required) Instance of @see
AP_Fieldobject.
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
)
);
}
}
}
Expand full source code Collapse full source code View on GitHub: lib/class-validate.php:438
Add your comment