複製代碼 代碼如下:
Form
複製代碼 代碼如下:
function form_sub()
{
if(!test_username(document.form1.username.value))
{
alert("姓名格式不正確");
return false;
}
if(!test_date(document.form1.birthday.value))
{
alert("日期格式不正確");
return false;
}
if(!test_email(document.form1.email.value))
{
alert("E-mail地址格式不正確");
return false;
}
if(!test_password(document.form1.password.value, document.form1.password2.value))
{
alert("兩次密碼輸入不相同");
return false;
}
}
function test_username(str_username)
{
var pattern = /[a-zA-Z_]/;
if(pattern.test(str_username))
return true;
else
return false;
}
function test_date(str_birthday)
{
var pattern = /[0-9]{4}-[0-9]{2}-[0-9]{2}/;
if(pattern.test(str_birthday))
return true;
else
return false;
}
function test_email(str_email)
{
var pattern = /^[a-zA-Z0-9_.]+@([a-zA-Z0-9_]+.)+[a-zA-Z]{2,3}$/;
if(pattern.test(str_email))
return true;
else
return false;
}
function test_password(str_p1, str_p2)
{
if(str_p1==str_p2)
return true;
else
return false;
}
複製代碼 代碼如下:
//本程式用於接收來自HTML頁面的表單資料並進行相應的驗證
$founderr = false; //初始化founderr變數,表示沒有錯誤
if(!ereg("[a-zA-Z_]", $_GET['username']))
{
echo "姓名格式不正確
";
$founderr = true;
}
if(!ereg("[0-9]{4}-[0-9]{2}-[0-9]{2}", $_GET['birthday']))
{
echo "日期格式不正確
";
$founderr = true;
}
if(!ereg("^[a-zA-Z0-9_.]+@([a-zA-Z0-9_]+.)+[a-zA-Z]{2,3}$", $_GET['email']))
{
echo "E-mail地址格式不正確
";
$founderr = true;
}
if($_GET['password'] != $_GET['password2'])
{
echo "兩次密碼輸入不相同";
$founderr = true;
}
if(!$founderr)
{
?>
Form
| 姓名: |
|
| 密碼: |
|
| 性別: |
|
| 生日: |
|
| E-mail: |
|
| 職業: |
|
}
?>
http://www.bkjia.com/PHPjc/319920.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/319920.htmlTechArticle複製代碼 代碼如下: html head titleForm/title meta http-equiv="Content-Type" content="text/html; charset=gb2312" script language="javascript" src="form.js" src="form.js"/scr...