()案例----JavaScript实现输入验证

需要验证的表单输入域和要求

用户名不能为空,是否符合规定的格式

密码长度是否超过6,两次密码输入一致

邮箱地址:邮箱地址必须符合邮箱形式

		一般用“buttom”类型按钮提交,提交时先执行“响应函数”	提交方式
input type="buttom" value="提交" onClick="响应函数"> ```
//JavaScript.js
function validate(){
var name=document.forms[0].userName.value;
var pwd=document.forms[0].userPwd.value;
var pwd1=document.form[0].userPwd1.value;
var email=document.form[0].userEmail.value;
var accept=document.form[0].accept.checked;
var reg1=/[a-zA-Z]\w*/;
var reg2=^w+([-+.']\w+)*@\w+([-.]\w+)*.\w+([-.]\w+)*/;
if(name.length<=0)
alert("用户名不能为空!");
else if(!reg1.test(name))
alert("用户名格式不正确!");
else if(pwd.length<6)
alert("密码长度必须大于等于6!");
else if(pwd1!=pwd)
alert("两次密码输入不正确!");
else if(!reg2.test(mail))
alert("邮件格式不正确!");
else document.form[0].submit();
}
```
然后在head head之间添加一行
```
<script language="java" src="JavaScript.js"></script>
```
最后,修改注册页面以及最后的“提交输入域”,如下
```
<input type="buttom" value="提交" onClick="validate()/">;
```

最新文章

  1. 免费开源的.NET多类型文件解压缩组件SharpZipLib(.NET组件介绍之七)
  2. iOS中sqlite版本号
  3. Mysql5.0以上 手工注入
  4. ogg 、 Shareplex和DSG RealSync 对比
  5. HDU 1407 测试你是否和LTC水平一样高(枚举)
  6. SmartCoder每日站立会议 01
  7. 第47章 授权端点(Authorize Endpoint) - Identity Server 4 中文文档(v1.0.0)
  8. ASP.NET MVC从空项目开始定制项目
  9. Bar 柱状图
  10. [Python]mysql-python 安装错误 fatal error C1083: Cannot open include file: &#39;config-win.h&#39;: No such file or directory
  11. nodejs高并发大流量的设计实现,控制并发的三种方法
  12. linux shell 指令搜索顺序
  13. MySQL processlist/kill
  14. Error:fatal: Not a git repository (or any of the parent directories): .git
  15. 关于sentinel LDK加密war包实现应用加密的使用方法
  16. tcp 大文件上传 ,切换目录 及登陆文件加盐处理
  17. JBoss Web和Tomcat的区别
  18. 设计模式--单例模式(学习Learning hard大神笔记实践)
  19. Oracle VM VisualBox 虚拟机创建共享文件夹。
  20. mongodb php auto increment 自增

热门文章

  1. Mybatis学习笔记12 - 动态sql之choose(when otherwise)标签
  2. 性能测试工具Jmeter02-安装配置
  3. [转]How to Create Custom Filters in AngularJs
  4. 在oracle RAC 环境下用 PL/SQL Developer debug procedure 出现 hang 的情况
  5. OpenStack Weekly Rank 2015.08.24
  6. 分布式任务框架elastic-job 学习笔记
  7. java 多线程 yield方法的意义
  8. php验证码处理
  9. tck/tl 以及expect脚本
  10. Oracle错误——ORA-03113:通信通道的文件结尾