PHP Date mailbox Address user name validation instance

Source: Internet
Author: User

<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 primarily used to check whether the submitted form data is wrong (validate)
The actual application of user input data testing (validate) and filtering (filter) are involved in the program security, very important, essential
In writing practical applications will not put the $_post directly in the function, here is a palliative solution, I hope we can correct

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 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;
}
?>

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.