Skip to content

Instantly share code, notes, and snippets.

@anthony9981
Last active August 22, 2024 14:31
Show Gist options
  • Select an option

  • Save anthony9981/08c9d13b5b0a2a56c2aac94a9d25aa22 to your computer and use it in GitHub Desktop.

Select an option

Save anthony9981/08c9d13b5b0a2a56c2aac94a9d25aa22 to your computer and use it in GitHub Desktop.
[Code Snippet] Thêm bộ lọc số điện thoại Việt Nam cho Elementor Pro
<?php
// Validate Tel in Elementor form
function elementor_form_validation( $record, $ajax_handler ) {
$fields = $record->get_field( [
'type' => 'tel',
] );
if ( empty( $fields ) ) {
return;
}
$field = current( $fields );
if (strlen($field['value']) < 8) {
$ajax_handler->add_error( $field['id'], esc_html__( 'Vui lòng nhập số điện thoại hợp lệ.', 'textdomain' ) );
}
// Match Vietnamese phone number format with optional country code
if ( preg_match( '/^(?:\+?84|0)(?:3[2-9]|5[6|8]|7[0|6|7|8|9]|8[1-5]|9[0-9])[0-9]{7}$/', $field['value'] ) !== 1 ) {
$ajax_handler->add_error( $field['id'], esc_html__( 'Vui lòng nhập số điện thoại hợp lệ.', 'textdomain' ) );
}
}
add_action( 'elementor_pro/forms/validation', 'elementor_form_validation', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment