PHP for date and email address and user name validation instance

Source: Internet
Author: User
Keywords Web Programming PHP Tutorials
Tags address date email email address error function mailbox name

PHP Tutorial Date mailbox Address User name authentication instance
<form id= "Form1" Name= "Form1" method= "Post" action= ""
  <label>name
  <input name= "name" type= "text" id= "name"/>
  </label>
  <p>
     <label>birthday
    <input name= "Birthday" type= "text" id= "Birthday"/>
    </label>
  </p>
  <P>
    <label> Email
    <input name= "Email" type= "text" id= "email"/>
    </label>
  </P>
  <p>
    <label>
    <input type= "Submit" Name= "submit" value= "submit"/>
    </label>
  </P>
</form
<?php
//This function is mainly used to check the error of the submitted form data (Validate)
//The actual application of user input data inspection (validate) and filter (filters) are involved in the program security, very important, Essential
//in writing the actual application will not put the $_post directly in the function, here is a palliative solution, I hope you can correct the

if ($_post)
{
 form_error ()
}
Function Form_error () {
    $_post[' name ' = Trim (strip_tags ($_post[' name '));//This is actually filter
    $len _name = strlen ($_post[' name '));
    if ($len _name > | | $len _name < 2) {
        $msg = ' Name length must be greater than 2 less than 30<br/> ';
   }
    $date = explode ('-', $_post[' birthday '));
    if (sizeof ($date)!= 3) {
        $msg. = ' Date format error <BR/ > ';
   } else {
        if (!checkdate ($date [1], $date [2], $ Date[0]) {
            $msg. = ' Incorrect date <br/> ';
       }
   }
    if (!eregi ("^[a-z ' 0-9]+ ([. _-][a-z ' 0-9]+) *@ ([a-z0-9]+ ([. _-][a-z0-9]+)] +$ ", $_post[' EMAIl ']) {
        $msg. = ' mailbox format error ';
   }
     return $msg;
}

 

Related Article

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.