Mặc dịnh của Field [tel*] của Contract Form 7 sẽ không bắt định dạng đúng số điện thoại theo chuẩn số điện thoại 10 số ở Việt Nam ở các nhà mạng viettel, mobi,... nên khi bạn xử lý người nhập sai số điện thoại sẽ không bắt đúng được. Để buộc người dùng nhập đúng vào số điện thoại 10 số bạn làm như sau: Truy cập vào function.php của themes bạn đang sử dụng và thêm code sau vào: Cách 1: code bắt đúng 10 số PHP: function custom_filter_wpcf7_is_tel( $result, $tel ) { $result = preg_match( '/^[+]?[0-9() -]*$/', $tel ); return $result;}add_filter( 'wpcf7_is_tel', 'custom_filter_wpcf7_is_tel', 10, 2 ); Cách 2: code bắt đúng 10 số bắt đầu phải là số 0 PHP: function custom_filter_wpcf7_is_tel( $result, $tel ) {$result = preg_match( '/^0(1\d{9}|9\d{8})$/', $tel );return $result;}add_filter( 'wpcf7_is_tel', 'custom_filter_wpcf7_is_tel', 10, 2 ); Hoặc PHP: //validate phone number phiên bản đại tràfunction custom_filter_wpcf7_is_tel( $result, $tel ) {$result = preg_match( '/^0(1d{9}|9d{8})$/', $tel );return $result;}add_filter( 'wpcf7_is_tel', 'custom_filter_wpcf7_is_tel', 10, 2 ); Cách 3: Code bắt chính xác số đầu tiên của số điện thoại PHP: function custom_filter_wpcf7_is_tel( $result, $tel ){$result = preg_match( '/^(09|03|07|08|05)+([0-9]{8})$/', $tel );return $result; }add_filter( 'wpcf7_is_tel', 'custom_filter_wpcf7_is_tel', 10, 2 ); Cách 4: tạo min max ở field nhập liệu lúc cấu hình form Mã: [tel* tel-396 minlength:10 maxlength:10] Cách 5: Bắt đầu số điện thoại hiện có ở VN PHP: function custom_filter_wpcf7_is_tel( $result, $tel ) { $result = preg_match( '/^(0|\+84)(\s|\.)?((3[2-9])|(5[689])|(7[06-9])|(8[1-689])|(9[0-46-9]))(\d)(\s|\.)?(\d{3})(\s|\.)?(\d{3})$/', $tel ); return $result;}add_filter( 'wpcf7_is_tel', 'custom_filter_wpcf7_is_tel', 10, 2 ); Cách 6: Bắt sđt theo các số hiện hành 2020 PHP: function custom_filter_wpcf7_is_tel( $result, $tel ) { $result = preg_match( '/^(032|033|034|035|036|037|038|039|086|096|097|098|081|082|083|084|085|088|091|094|056|058|092|070|076|077|078|079|089|090|093|099|059)+([0-9]{7})$/;', $tel ); return $result;}add_filter( 'wpcf7_is_tel', 'custom_filter_wpcf7_is_tel', 10, 2 );