简单的 表单验证

<script type="text/javascript">
        $(function () {
           
            $("#birthday").datepick({ dateFormat: 'yyyy-mm-dd',yearRange: '1900:2020' });
           
              $('#sendBtn').click(function(){
                  if($.trim($('#testname').val()) == ''||$.trim($('#testname').val()) == '请输入您的姓名'){
                    alert("请填写姓名!");
                    $('#testname').focus();
                    return;
                }
                  if (($.trim($('#testname').val()).length>30)||($.trim($('#testname').val()).length<2)) {
                    alert("请输入正确的姓名!");
                    $('#testname').focus();
                    return;
                }
                if($.trim($('#birthday').val()) == ''||$.trim($('#birthday').val()) == '请输入您的生日'){
                    alert("请填写生日!");
                    $('#birthday').focus();
                    return;
                }
                if (/^(\d{4})([-])(\d{2})([-])(\d{2})/.test($.trim($('#birthday').val())) == false) {
                    alert("日期格式不正确!\n正确格式为:1988-04-28");
                    $('#birthday').focus();
                    return;
                }
                if($.trim($('#phone').val()) == ''||$.trim($('#phone').val()) == '请输入您的手机号码'){
                    alert("请填写手机!");
                    $('#phone').focus();
                    return;
                }
                if (/0{0,1}(13[0-9]|15[3-9]|15[0-2]|18[0-9])[0-9]{8}$/.test($.trim($('#phone').val())) == false) {
                    alert("请输入正确11位有效的手机号码!");
                    $('#phone').focus();
                    return;
                }
                if($.trim($('#email').val()) == ''||$.trim($('#email').val()) == '请输入您的邮箱地址'){
                    alert("请填写邮箱!");
                    $('#email').focus();
                    return;
                }
                if (/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test($.trim($('#email').val())) == false) {
                    alert("邮箱格式不正确!");
                    $('#email').focus();
                    return;
                }
                if (($.trim($('#email').val()).length>31)||($.trim($('#email').val()).length<7)) {
                    alert("请输入正确的邮箱!");
                    $('#email').focus();
                    return;
                }
                document.getElementById('sendBtn').style.display = 'none';
                document.getElementById('msgspan').style.display = 'block';
                $.post("/front/website/testuser/getReport",
                    {testname:$("#testname").val(),
                    birthday:$("#birthday").val(),
                     phone:$("#phone").val(),
                     email:$("#email").val()
                    },
                function(date){
                    alert("报告已发送,请注意查收!");
                    document.getElementById('msgspan').style.display = 'none';
                    document.getElementById('sendBtn').style.display = 'block';
                });
            });
        });
        
    </script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值