2015-08-28 107 views
0

電子郵件地址和手機號碼字段我有如下腳本:驗證在JavaScript

$(function() { 
    $(".submit").click(function() { 
     var full_name = $("#full_name").val(); 
     var cell_phone = $("#cell_phone").val(); 
     var email = $("#email").val(); 
     var dataString = 'full_name='+ full_name + '&cell_phone=' + cell_phone + '&email=' + email; 
     if (full_name=='' || cell_phone=='' || email=='') 
     { 
      $('.success').fadeOut(200).hide(); 
      $('.error').fadeOut(200).show();  
     } 
     else 
     { 
      $.ajax({ 
       type: "POST", 
       url: "join.php", 
       data: dataString, 
       success: function() { 
        $('.submit').fadeIn(200).hide(); 
        $('.success').fadeIn(200).show(); 
        $('.error').fadeOut(200).hide(); 
       } 
      }); 
     } 
     return false; 
    }); 
}); 
  1. 如何使驗證電子郵件。
  2. 僅(號碼+-)和日提交不少於7號碼cell_phone。
+1

1'' – dandavis

+0

另一種選擇是簡單的正則表達式中使用在其最好 – NendoTaka

+0

電子郵件驗證正則表達式 https://www.youtube.com/watch?v= qmuXqZi3r5M – Buddhi741

回答

0

is.jsemailphone驗證器可以解決。

$(function() { 
    $(".submit").click(function() { 
     var full_name = $("#full_name").val(); 
     var cell_phone = $("#cell_phone").val(); 
     var email = $("#email").val(); 
     var dataString = 'full_name='+ full_name + '&cell_phone=' + cell_phone + '&email=' + email; 
     if (full_name=='' || is.not.eppPhone(cell_phone) || is.not.email(email)) 
     { 
      $('.success').fadeOut(200).hide(); 
      $('.error').fadeOut(200).show();  
     } 
     else 
     { 
      $.ajax({ 
       type: "POST", 
       url: "join.php", 
       data: dataString, 
       success: function() { 
        $('.submit').fadeIn(200).hide(); 
        $('.success').fadeIn(200).show(); 
        $('.error').fadeOut(200).hide(); 
       } 
      }); 
     } 
     return false; 
    }); 
});