2017.11.9 如何利用JS做登陆验证界面
2024-10-20 03:57:18
()案例----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()/">;
```
最新文章
- 免费开源的.NET多类型文件解压缩组件SharpZipLib(.NET组件介绍之七)
- iOS中sqlite版本号
- Mysql5.0以上 手工注入
- ogg 、 Shareplex和DSG RealSync 对比
- HDU 1407 测试你是否和LTC水平一样高(枚举)
- SmartCoder每日站立会议 01
- 第47章 授权端点(Authorize Endpoint) - Identity Server 4 中文文档(v1.0.0)
- ASP.NET MVC从空项目开始定制项目
- Bar 柱状图
- [Python]mysql-python 安装错误 fatal error C1083: Cannot open include file: &#39;config-win.h&#39;: No such file or directory
- nodejs高并发大流量的设计实现,控制并发的三种方法
- linux shell 指令搜索顺序
- MySQL processlist/kill
- Error:fatal: Not a git repository (or any of the parent directories): .git
- 关于sentinel LDK加密war包实现应用加密的使用方法
- tcp 大文件上传 ,切换目录 及登陆文件加盐处理
- JBoss Web和Tomcat的区别
- 设计模式--单例模式(学习Learning hard大神笔记实践)
- Oracle VM VisualBox 虚拟机创建共享文件夹。
- mongodb php auto increment 自增
热门文章
- Mybatis学习笔记12 - 动态sql之choose(when otherwise)标签
- 性能测试工具Jmeter02-安装配置
- [转]How to Create Custom Filters in AngularJs
- 在oracle RAC 环境下用 PL/SQL Developer debug procedure 出现 hang 的情况
- OpenStack Weekly Rank 2015.08.24
- 分布式任务框架elastic-job 学习笔记
- java 多线程 yield方法的意义
- php验证码处理
- tck/tl 以及expect脚本
- Oracle错误——ORA-03113:通信通道的文件结尾