js校验表单中数据格式及数字类型

<script type="text/javascript">   
    function isNumberInt(form){   
        var rtnBoolean = false;   
           
        var phoneParam = form.phone.value;   
        var mobileParam = form.mobile.value;   
           
        var enterPhone1 = "请输入联系电话!";   
        var enterPhone2 = "请输入真实的联系电话!";   
        var numberPhone = "联系电话,请输入数字!";   
        rtnBoolean = validLength(phoneParam,1,7,enterPhone1,enterPhone2);   
        if(rtnBoolean == false){   
            return rtnBoolean;   
        }   
           
        rtnBoolean = validNumber(phoneParam,numberPhone);   
        if(rtnBoolean == false){   
            return rtnBoolean;   
        }   
           
           
        var enterMobile1 = "请输入手机号码!";   
        var enterMobile2 = "请输入真实的手机号码!";   
        var numberMobile = "手机号码,请输入数字!";   
           
        rtnBoolean = validLength(mobileParam,1,11,enterMobile1,enterMobile2);   
        if(rtnBoolean == false){   
            return rtnBoolean;   
        }   
           
        rtnBoolean = validNumber(mobileParam,numberMobile);   
        if(rtnBoolean == false){   
            return rtnBoolean;   
        }   
           
        return true;   
    }   
  
    function validLength(param,minLength,stdLength,alertParam1,alertParam2){   
        if(param.length < minLength){   
            alert(alertParam1);   
            return false;   
        }   
           
        if(param.length < stdLength){   
            alert(alertParam2);   
            return false;   
        }   
    }   
       
    function validNumber(param,numberPhone){   
        for (i = 0;i < param.length;i++){   
            ch = param.charAt(i);   
            if(ch<'0'||ch>'9'){   
                alert(numberPhone);   
                    return false;   
            }   
        }      
    }   
  
</script>  

 

 

<form name="msgForm" action="提交的路径" method=post>  
                <table class="word">                      
                    <tr>    
                      <td height="25"><div align="right">标题:</div></td>  
                      <td colspan="2"><input name="headline" type="text" size="40"> <font color="#FF0000">  
                        *</font></td>  
                    </tr>                       
                    <tr>    
                      <td height="25"><div align="right">用户名:</div></td>  
                      <td colspan="2"><input name="userName" type="text"> <font color="#FF0000">    
                        *</font></td>  
                    </tr>                       
                    <tr>    
                      <td height="25"><div align="right">公司名:</div></td>  
                      <td colspan="2"><input name="companyName" type="text" size="40"> <font color="#FF0000">    
                        *</font></td>  
                    </tr>                       
                    <tr>    
                      <td height="25"><div align="right">联系电话:</div></td>  
                      <td colspan="2"><input name="phone" type="text"></td>  
                    </tr>                       
                    <tr>    
                      <td height="25"><div align="right">手机:</div></td>  
                      <td colspan="2"><input name="mobile" type="text"></td>  
                    </tr>  
                    <tr>    
                      <td height="25"><div align="right">电子邮件</div></td>  
                      <td colspan="2"><input type="text" name="email"></td>  
                    </tr>  
                    <tr>    
                      <td height="25"><div align="right">邮政编码:</div></td>  
                      <td colspan="2"><input type="text" name="textfield5"></td>  
                    </tr>                       
                    <tr>    
                      <td height="25"><div align="right">留言内容:</div></td>  
                      <td colspan="2">  
                        <textarea name="msgContent" cols="40" rows="10"></textarea>  
                      </td>  
                    </tr>  
                    <tr>    
                      <td> </td>  
                      <td width="9%">  
                        <input type="submit" name="submit" value="提交" οnclick="return isNumberInt(msgForm);">  
                      </td>  
                      <td width="66%"><input type="reset" name="reset" value="重置"></td>  
                    </tr>  
                </table>                     
</form>  

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值