PHP Form Validation Implementation Code _php tutorial

Source: Internet
Author: User
Copy CodeThe code is as follows:


<title>Form</title>










Copy CodeThe code is 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 ("date format is incorrect");
return false;
}

if (!test_email (Document.form1.email.value))
{
Alert ("e-mail address format is incorrect");
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 CodeThe code is as follows:
This program is used to receive form data from an HTML page and to validate it accordingly
$founderr = false; Initialize the FOUNDERR variable to indicate no error
if (!ereg ("[A-za-z_]", $_get[' username ']))
{
echo "name format is incorrect
";
$founderr = true;
}

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

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

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

if (! $founderr)
{
?>


<title>Form</title>





























Name:
Password:
Gender:
Birthday:
E-Mail:
Occupational:



}
?>

http://www.bkjia.com/PHPjc/319920.html www.bkjia.com true http://www.bkjia.com/PHPjc/319920.html techarticle Copy the code code as follows: HTML head titleform/title meta http-equiv= "Content-type" content= "text/html; charset=gb2312" script language= "JavaScript" src= "Form.js" src= "Form.js"/scr ...

  • 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.