【问题标题】:Validate email address and cell phone number field in JavaScript在 JavaScript 中验证电子邮件地址和手机号码字段
【发布时间】:2015-11-23 15:50:56
【问题描述】:

我有以下脚本:

$(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. 只有 (numbers + -) 且不少于 7 个号码的手机号码。

【问题讨论】:

标签: javascript jquery ajax


【解决方案1】:

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;
    });
});

【讨论】:

    【解决方案2】:
    var re = /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
    var phoneno = /^\+?(?:[0-9] ?){6,14}[0-9]$/;
    if (full_name=='' || !phoneno.test(cell_phone) || !re.test(email))
    

    【讨论】:

      猜你喜欢
      • 2018-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-12
      • 1970-01-01
      • 1970-01-01
      • 2011-11-07
      • 2011-11-15
      相关资源
      最近更新 更多