Kiểm tra Validate đúng số điện thoại trong Field Tel Contact Form 7

Thảo luận trong 'Mã nguồn mở Wordpress' bắt đầu bởi seolagi, 15/10/20.

  1. seolagi
    Tham gia ngày:
    16/4/14
    Bài viết:
    1,029
    Đã được thích:
    81
    Điểm thành tích:
    48
    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);
    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);
    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);
    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); 
    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);
    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); 
     
    Cảm ơn đã xem bài:

    Kiểm tra Validate đúng số điện thoại trong Field Tel Contact Form 7

    Last edited by a moderator: 1/4/22


Chủ để tương tự : Kiểm Validate
Diễn đàn Tiêu đề Date
Mã nguồn mở Wordpress Kiểm tra Validate đúng số điện thoại ở comment wordpress như thế nào? 10/12/20
Mã nguồn mở Wordpress Xóa tháng năm trên kết quả tìm kiếm google trong wordpress 18/12/19
Mã nguồn mở Wordpress Remover Xóa schema.org/AggregateRating kk Star Ratings cấu trúc dữ liệu trên tìm kiếm google 28/5/19
Mã nguồn mở Wordpress Cách gắn nút tìm kiếm vào header web wordpress 1/7/17