表单正则验证简便方法

<form action="/swt/" method="" name="gh_form" onSubmit="javascript:return check();">
    <p>
        <label>就诊姓名:</label>
        <input type="text" name="name" placeholder="请输入您的姓名" class="input" />
    </p>
    <p>
        <label>就诊日期:</label>
        <input type="date" name="date" placeholder="年/月/日" class="input"/>
    </p>
    <p>
        <label>联系方式:</label>
        <input type="text" name="phone" placeholder="请输入您的手机号码" class="input" id="phone_1" maxlength="11"/>
        <a href="tel:0756-8592828" id="phone">免费电话</a>
    </p>
    <p>
        <label id="ms">病情描述:</label>
        <textarea name="description" id="des" class="ms" placeholder="例如:脸上痘痘很多…"></textarea>
    </p>
    <p>
        <input type="submit" value="提交挂号信息" id="submit" />
    </p>
</form>

<script>
     function check() {
        var re=/[\u4E00-\u9FA5]/g;
        if(document.gh_form.name.value==''){
            alert('请填写姓名!');return false;
        }else if(!re.test(gh_form.name.value)){
            alert('请填写中文姓名!');return false;
        }
        var istel=/^(?:13\d|18\d|15\d)\d{5}(\d{3}|\*{3})$/;
        if(!istel.test(gh_form.phone.value)){
            alert("请正确填写电话号码");return false;
        }
    }
</script>

 

posted @ 2019-05-02 10:30  冷晨  阅读(175)  评论(0编辑  收藏  举报