简单表单提交验证效果js实现

管理员 发布于 6年前   372
<form action="url" enctype="multipart/form-data" method="post" onSubmit="return check()">
<table>
<tr>
<td>
<input type='text' name='phone' id='phone' style='width: 25px;border: 1px solid #E5E5E5;
    height: 30px;border-radius: 10px;' placeholder="(必填) 请输入手机号" />
</td>
</tr>
<tr>
<td>
<input type='text' name='xmname' id='xmname' style='width: 25px;border: 1px solid #E5E5E5;
    height: 30px;border-radius: 10px;'placeholder="(必填) 请输入姓名" />
</td>
</tr>
</table>
<div>
    <input type="submit" name="submit" value="提交" />
</div>
</form>

<script>
  function check()
  {
    re = /^1\d{10}$/
    tel=document.getElementById("phone").value;
    if (re.test(tel)) {
    } else {
        alert("请输入正确的手机号!");
        return false;
    }
    name=document.getElementById("xmname").value;
    if(name=="")
    {
      alert("请输入姓名!")
      return false;
    }
 }
</script>

简单的弹窗效果:不改都能用

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!

该博客于2020-12-7日,后端基于go语言的beego框架开发
前端页面使用Bootstrap可视化布局系统自动生成

是我仿的原来我的TP5框架写的博客,比较粗糙,底下是入口
侯体宗的博客

      订阅博客周刊

文章标签

友情链接

HouTiZong
侯体宗的博客
© 2020 zongscan.com
版权所有ICP证 : 粤ICP备20027696号
PHP交流群
侯体宗的博客