PHP Form Verification Implementation Code _php Foundation

Source: Internet
Author: User
Copy Code code as follows:

<title>Form</title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<script language= "javascript" src= "Form.js" src= "Form.js" ></script>

<body>
<form action= "post.php" method= "Get" Name= "Form1" onsubmit= "Return Form_sub ()" >
<table width= "271" border= "0" align= "center" cellpadding= "0" cellspacing= "0" >
<tr>
&LT;TD width= "><div" align= "right" > name:</div></td>
&LT;TD width= "186" ><input name= "username" type= "text" id= "username" ></td>
</tr>
<tr>
<td><div align= "Right" > Password:</div></td>
<td><input name= "password" type= "password" id= "password" ></td>
</tr>
<tr>
<td><div align= "Right" > Password confirmation:</div></td>
<td><input name= "password2" type= "password" id= "Password2" ></td>
</tr>
<tr>
<td><div align= "right" > Sex:</div></td>
<td><select name= "Sex" id= "sex" >
<option value= "0" selected> male </option>
<option value= "1" > Women </option>
</select></td>
</tr>
<tr>
<td><div align= "Right" > Birthday:</div></td>
<td><input name= "Birthday" type= "text" id= "Birthday" ></td>
</tr>
<tr>
<td><div align= "right" >E-mail:</div></td>
<td><input name= "Email" type= "text" id= "email" ></td>
</tr>
<tr>
<td><div align= "Right" > Career:</div></td>
<td><input name= "Job" type= "text" id= "Job" ></td>
</tr>
</table>
<p align= "center" >
<input type= "Submit" value= "Submit" >
<input type= "reset" value= "reset" >
</p>
</form>
</body>


Copy Code code as follows:

function Form_sub ()
{
if (!test_username (Document.form1.username.value))
{
Alert ("Incorrect name format");
return false;
}

if (!test_date (Document.form1.birthday.value))
{
Alert ("Incorrect date format");
return false;
}

if (!test_email (Document.form1.email.value))
{
Alert ("e-mail address format is not correct");
return false;
}

if (!test_password (Document.form1.password.value, Document.form1.password2.value))
{
Alert ("Two times password input is not the same");
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;
}


Copy Code code as follows:

<?php
This program is used to receive form data from HTML pages and verify accordingly
$founderr = false; Initialize FOUNDERR variable to indicate no error
if (!ereg ("[A-za-z_]", $_get[' username '))
{
echo "Incorrect name format <BR>";
$founderr = true;
}

if (!ereg ("[0-9]{4}-[0-9]{2}-[0-9]{2}", $_get[' birthday '))
{
echo "Incorrect date format <BR>";
$founderr = true;
}

if (!ereg ("^[a-za-z0-9_.] +@ ([a-za-z0-9_]+.) +[a-za-z]{2,3}$ ", $_get[' email '))
{
echo "Incorrect e-mail address format <BR>";
$founderr = true;
}

if ($_get[' password ']!= $_get[' Password2 ')
{
echo "Two times password input is not the same";
$founderr = true;
}

if (! $founderr)
{
?>
<title>Form</title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">

<body>
<table width= "271" border= "0" align= "center" cellpadding= "0" cellspacing= "0" >
<tr>
&LT;TD width= "><div" align= "right" > name:</div></td>
&LT;TD width= "186" ><?php echo $_get[' username ']?></td>
</tr>
<tr>
<td><div align= "Right" > Password:</div></td>
<td><?php echo $_get[' password ']?></td>
</tr>
<tr>
<td><div align= "right" > Sex:</div></td>
<td><?php if ($_get[' sex ']==0) echo "male"; else echo "female"?></td>
</tr>
<tr>
<td><div align= "Right" > Birthday:</div></td>
<td><?php echo $_get[' birthday ']?></td>
</tr>
<tr>
<td><div align= "right" >E-mail:</div></td>
<td><?php echo $_get[' email ']?></td>
</tr>
<tr>
<td><div align= "Right" > Career:</div></td>
<td><?php echo $_get[' job ']?></td>
</tr>
</table>
</body>
<?php
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.