Validate elelmentor form field to accept only digits and no other character (in
-
Hi there,
How to limit the accepted number of characters in text or tel filed?(in my case 11 only)
Also how to validate the field to accept only numbers and no other characters?
I am using this from the elementor form API page. but my regex format is not right I guess.// Validate the Tel field is in XXXXXXXXXX 01234567899 format.
add_action( ‘elementor_pro/forms/validation’, function ( $record, $ajax_handler ) {
$fields = $record->get_field( [
‘id’ => ‘ir_tel_format’,
] );if ( empty( $fields ) ) {
return;
}$field = current( $fields );
if ( 1 !== preg_match( ‘/[0-9]{11}/’, $field[‘value’] ) ) {
$ajax_handler->add_error( $field[‘id’], ‘eroor message’ );
}
}, 10, 2 );Thanks
- The topic ‘Validate elelmentor form field to accept only digits and no other character (in’ is closed to new replies.