码迷,mamicode.com
首页 > 编程语言 > 详细

JavaScript表单项数据过滤代码

时间:2014-12-16 22:42:14      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:javascript   数据   验证码   密码   表单   

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<script type="text/javascript">
	window.onload = function(){
		document.getElementById("admin").focus();	
	}
	function check_admin(admininfo){
		if(admininfo==null || admininfo.length == 0 || !new RegExp(/^[a-zA-Z]{3,20}$/).test(admininfo)){
			return false ;
		}else{
			return true ;
		}
	}
	function check_pwd(pwdinfo){
		if(pwdinfo==null || pwdinfo.length == 0 || !new RegExp(/^\d{6}$/).test(pwdinfo)){
			return false ;
		}else{
			return true ;
		}
	}
	function check_yzm(yzminfo){
		if(yzminfo==null || yzminfo.length == 0 || !new RegExp(/^[A-Za-z0-9]{5}$/).test(yzminfo)){
			return false ;
		}else{
			return true ;
		}
	}
	
	function onblur_show_admin_success_msg(){
		var admin = document.getElementById("admin").value ;
		var flag = check_admin(admin);
		if(flag){
			document.getElementById("admin_msg").innerHTML = "<b style='color:green;'>格式正确!</b>" ;
		}else{
			document.getElementById("admin_msg").innerHTML = "管理员账号有误,请重新填写!" ;
		}
	}
	function onblur_show_pwd_success_msg(){
		var pwd = document.getElementById("pwd").value ;
		var flag = check_pwd(pwd) ;
		if(flag){
			document.getElementById("pwd_msg").innerHTML = "<b style='color:green;'>格式正确!</b>" ;
		}else{
			document.getElementById("pwd_msg").innerHTML = "管理员密码有误,请重新填写!" ;
		}
	}
	function onblur_show_yzm_success_msg(){
		var yzm = document.getElementById("yzm").value ;
		var flag = check_yzm(yzm) ;
		if(flag){
			document.getElementById("yzm_msg").innerHTML = "<b style='color:green;'>格式正确!</b>" ;
		}else{
			document.getElementById("yzm_msg").innerHTML = "验证码有误,请重新填写!" ;
		}
	}
	
	function clear_admin_msg(){
		document.getElementById("admin_msg").innerHTML = "" ;
	}	
	function clear_pwd_msg(){
		document.getElementById("pwd_msg").innerHTML = "" ;
	}	
	function clear_yzm_msg(){
		document.getElementById("yzm_msg").innerHTML = "" ;
	}	
	
	
	function onsubmit_check_all_data(){
		var admin = document.getElementById("admin").value ;
		var pwd = document.getElementById("pwd").value ;
		var yzm = document.getElementById("yzm").value ;
		if(!check_admin(admin)||!check_pwd(pwd)||!check_yzm(yzm)){
			return false ;
		}
		/*
		var flag_admin = check_admin(admin) ;
		var flag_pwd = check_pwd(pwd);
		var flag_yzm = check_yzm(yzm);
		if(flag_admin&&flag_pwd&&flag_yzm){
			return true ;
		}else{
			return false ;
		}
		if(!flag_admin||!flag_pwd||!flag_yzm){
			return false ;
		}
		*/
	}
</script>
		<div class="body">
			<div class="login">
				<form action="login.action" method="post" class="loginform" onsubmit="return onsubmit_check_all_data();">
					<fieldset>
						<legend>系统管理员登陆窗口</legend>
						<div class="margin_padding"></div>
					<p>
						<label for="admin">管理员账号</label><br/>
						<span class="margin_padding"></span>
						<input type="text" name="admin" id="admin" style="width:200px;height:25px;" onfocus="clear_admin_msg();" onblur="onblur_show_admin_success_msg();">
						<span id="admin_msg" style="color: red;font-style: italic;"></span>
					</p>
					<span class="margin_padding"></span>
					<p>
						<label for="pwd">管理员密码</label><br/>
						<span class="margin_padding"></span>
						<input type="password" name="pwd" id="pwd" style="width:200px;height:25px;" onfocus="clear_pwd_msg();" onblur="onblur_show_pwd_success_msg();">
						<span id="pwd_msg" style="color: red;font-style: italic;"></span>
					</p>
					<span class="margin_padding"></span>
					<p>
						<label for="yzm">输入验证码</label><span style="color:#555;font-size:10px;">(看不清楚,请点击图片刷新!)</span><br>
						<span class="margin_padding"></span>
						<input type="text" name="yzm" id="yzm" style="width:100px;height:25px;" onfocus="clear_yzm_msg();"  onblur="onblur_show_yzm_success_msg();">
						<img alt="loading..." src="yzm.action" style="width:100px;height:25px;" id="yzmpic" onclick="refrushyzm();" onmouseover="showpointer();">
						<span id="yzm_msg" style="color: red;font-style: italic;"></span>
					</p>
					<span class="margin_padding"></span>
					<p>
						<input type="submit" value="管理员登录" id="submit">
					</p>
					<span class="margin_padding"></span>
					</fieldset>
				</form>
			</div>
		</div>

JavaScript表单项数据过滤代码

标签:javascript   数据   验证码   密码   表单   

原文地址:http://blog.csdn.net/responsecool/article/details/41967335

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!