Last active
August 22, 2024 14:31
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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