DRP中用到的JavaScript验证
在Drp中添加按钮的时候要验证用户输入的是否合法利用JavaScript就可以实现这个功能下面就是我的代码。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<script src="client_validate.js"></script>
<script type="text/javascript">
function goBack() {
window.self.location="user_maint.html"
} function addUser() {
var vUserId=document.getElementById("userId");
var vUserName=document.getElementById("userName");
var vPassword=document.getElementById("password");
var vContactTel=document.getElementById("contactTel");
var vEmail=document.getElementById("email"); /**用户代码验证**/
//用户代码不能为空
if(trim(vUserId.value)==""){
alert("用户代码不能为空!");
vUserId.focus();
return;
}
//判断字符长度大于4
if(trim(vUserId.value).length<4){
alert("用户代码长度不能小于4!");
vUserId.focus();
vUserId.select();
return;
} //用户代码只能是数字和字母
var re=new RegExp(/^[0-9a-zA-Z]{4,6}$/);
if(!re.test(trim(vUserId.value)))
{
alert("用户代码必须是字母或数字,只能为4~6位");
vUserId.focus();
vUserId.select();
return ;
} //第一个字符为字母
re.compile(/^[a-zA-Z]/);
if(!re.test(trim(vUserId.value)))
{
alert("用户代码首字符必须是字母");
vUserId.focus();
vUserId.select();
return ;
} /**用户名称验证**/
//用户名必须输入
if(trim(vUserName.value)==""){
alert("用户名称不能为空!");
vUserName.focus();
vUserName.select();
return;
} //用户名不能和用户代码一样
if(trim(vUserName.value)==trim(vUserId.value)){
alert("用户名不能和用户代码一样!");
vUserName.focus();
vUserName.select();
return;
} /**密码验证**/
//判断密码字符长度大于6
if(trim(vPassword.value).length<6){
alert("密码长度不能小于6!");
vPassword.focus();
vPassword.select();
return;
} /**联系电话验证**/
//如果联系电话不为空则验证联系电话为数字
if (trim(vContactTel.value) != "") {
//采用正则
re.compile(/^[0-9]+$/);
if (!re.test(vContactTel.value)) {
alert("电话号码不合法!");
vContactTel.focus();
return;
}
} /**Email验证**/
if(trim(vEmail.value)!=""){
re.compile(/^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/);
if(!re.test(trim(vEmail.value))){
alert("Email不合法!");
vEmail.focus();
vEmail.select();
return;
}
} /* document.getElementById("userForm").action="user_add.jsp";
document.getElementById("userForm").method="post";
document.getElementById("userForm").submit(); */
with (document.getElementById("userForm")){
action="user_add.jsp";
method="post";
submit();
} } function linit(){
document.getElementById("userId").focus();
}
/*禁止输入除了字母以外的东西*/
function userIdOnKeyPress(){
if(!(event.keyCode>=97 && event.keyCode<=122)){
event.keyCode=0;
}
}
/*按回车键变为Tab键,如果到了添加按钮则提交数据*/
function document.onkeydown() {
if(window.event.keyCode==13 && window.event.srcElement.type!='button'){
window.event.keyCode=9;
}
}
</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head> <body class="body1" onload="linit()">
<form name="userForm" target="_self" id="userForm">
<div align="center">
<table width="95%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td> </td>
</tr>
</table>
<table width="95%" border="0" cellspacing="0" cellpadding="0"
height="25">
<tr>
<td width="522" class="p1" height="25" nowrap>
<img src="../images/mark_arrow_03.gif" width="14" height="14">
<b>系统管理>>用户维护>>添加</b>
</td>
</tr>
</table>
<hr width="97%" align="center" size=0>
<table width="95%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="22%" height="29">
<div align="right">
<font color="#FF0000">*</font>用户代码:
</div>
</td>
<td width="78%">
<input name="userId" type="text" class="text1" id="userId"
size="10" maxlength="10" onkeypress="userIdOnKeyPress();">
</td>
</tr>
<tr>
<td height="26">
<div align="right">
<font color="#FF0000">*</font>用户名称:
</div>
</td>
<td>
<input name="userName" type="text" class="text1" id="userName"
size="20" maxlength="20">
</td>
</tr>
<tr>
<td height="26">
<div align="right">
<font color="#FF0000">*</font>密码:
</div>
</td>
<td>
<label>
<input name="password" type="password" class="text1"
id="password" size="20" maxlength="20">
</label>
</td>
</tr>
<tr>
<td height="26">
<div align="right">
联系电话:
</div>
</td>
<td>
<input name="contactTel" type="text" class="text1"
id="contactTel" size="20" maxlength="20">
</td>
</tr>
<tr>
<td height="26">
<div align="right">
email:
</div>
</td>
<td>
<input name="email" type="text" class="text1" id="email"
size="20" maxlength="20">
</td>
</tr>
</table>
<hr width="97%" align="center" size=0>
<div align="center">
<input name="btnAdd" class="button1" type="button" id="btnAdd"
value="添加" onClick="addUser()">
<input name="btnBack" class="button1" type="button" id="btnBack"
value="返回" onClick="goBack()" />
</div>
</div>
</form>
</body>
</html>
DRP中用到的JavaScript验证的更多相关文章
- Eclipse去除JavaScript验证错误
这篇文章主要是对Eclipse去除js(JavaScript)验证错误进行了介绍.在Eclipse中,js文件常常会报错.可以通过如下几个步骤解决 第一步: 去除eclipse的JS验证: 将wind ...
- JavaScript验证正则表达式大全
JavaScript验证正则表达式大全,搜集最全的JavaScript验证正则表达式,开始查看吧,这里的都是正则表达式的例子,具体和函数结合的使用方法,还请查看下篇文章<JavaScript使用 ...
- 【转】Eclipse去除js(JavaScript)验证错误
这篇文章主要是对Eclipse去除js(JavaScript)验证错误进行了介绍.在Eclipse中,js文件常常会报错.可以通过如下几个步骤解决 第一步:去除eclipse的JS验证:将window ...
- javascript 验证 yyyy-MM-dd HH:mm:ss 的正则表达式
原文:javascript 验证 yyyy-MM-dd HH:mm:ss 的正则表达式 ^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13 ...
- 使用JavaScript验证用户输入的是否为正整数
在项目开发中,需要使用JavaScript验证用户输入的是否为正整数. 方法一: var type="^[0-9]*[1-9][0-9]*$"; var r=new RegExp( ...
- 纯javascript验证,100行超精简代码。
这篇文章转自--寒飞,原帖地址http://blog.csdn.net/luoyehanfei/article/details/42262249 QQ交流群235032949 纯javascript验 ...
- 转发 eclipse 取消javascript 验证
博客地址: http://blog.csdn.net/itchiang/article/details/7498474 最近出了一个很怪的现象,某一个js文件,在某一个Eclipse工程中呆的好好的, ...
- JavaScript验证函数大全
1. 长度限制 <script> function test() { if(document.a.b.value.length>50) { alert("不能超过50个字符 ...
- 常用的JavaScript验证正则表达式1
匹配Email地址的正则表达式:w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*评注:表单验证时很实用 匹配网址URL的正则表达式:[a-zA-z]+://[^s]* 评注:网 ...
随机推荐
- 《Cortex-M0权威指南》之体系结构---嵌套中断控制器(NVIC)
转载请注明来源:cuixiaolei的技术博客 为了管理中断请求的优先级并处理其他异常,Cortex-M0处理器内置了嵌套中断控制器(NVIC).NVIC的一些可编程控制器控制着中断管理功能,这些寄存 ...
- IOS缓存之NSCache缓存
NSCache:专门做缓存的类 NSCache简介:NSCache是苹果官方提供的缓存类,用法与NSMutableDictionary的用法很相似,在AFNetworking和SDWebImage中, ...
- IceFig阅读笔记
嗯:就是这里了 http://research.worksap.com/research/icefig/ 一下阅读笔记: 嗯,时间有限,他们提供的又茫茫多,所以 就找出来了 几个 单独聊聊吧. 其他语 ...
- 解决IE下z-index的bug
IE下z-index有很奇葩的BUG,就是z-index级别不生效.解决方案只有在 该元素的父级元素添加 posotion和z-index,就能识别了. element{position:relati ...
- 获取https证书
获取证书 个人如果想购买SSL证书,相对来说还是比较简单的.对于小型网站,可以考虑通过StartSSL获取免费证书.另外还可以通过LetsEncrypt项目使用一个简单的命令行界面为服务获取免费证书. ...
- Part 32 Abstract classes in c#
- File.Create创建文件后,需要释放资源
if (!File.Exists(SavePath)) { File.Create(SavePath).Close(); }
- Cocos2d-JS事件处理机制
在很多图形用户技术中,事件处理机制一般都有三个重要的角色:事件.事件源和事件处理者.事件源是事件发生的场所,通常就是各个视图或控件,事件处理者是接收事件并对其进行处理的一段程序.事件处理机制中三个角色 ...
- button等按钮onclientclick事件失效
如果确定JS没写错 第一种方法: 在JS方法最后return false; 调用方法前加上return 第二种方法: 在JS方法最后event.returnValue=false; 附加:event. ...
- (转)Linux vmstat命令实战详解
vmstat命令是最常见的Linux/Unix监控工具,可以展现给定时间间隔的服务器的状态值,包括服务器的CPU使用率,内存使用,虚拟内存交换情况,IO读写情况.这个命令是我查看Linux/Unix最 ...