DRPで使うJavaScriptの検証
8213 ワード
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>
ダウンロードが必要なJs