Php trim () form verification is not empty

Source: Internet
Author: User
Tags php tutorial

In the php Tutorial, trim () form verification is not a null instance. It should be an entry-level instance. It tells you how to use the trim function to delete spaces and determine whether the data submitted by the user is empty.

<Html>
<Body>
<Form method = "post" action = "formerrorcheck. php">
<H1> contact information <Table>

<Tr>
<Td> <B> nickname: </B> </td>
<Td> <input type = "text" name = "nickname"> </td>
</Tr>

<Tr>
<Td> title: </td>
<Td> <input type = "text" name = "title"> </td>
</Tr>

<Tr>
<Td> <B> first name: </B> </td>
<Td> <input type = "text" name = "firstname"> </td>
</Tr>

<Tr>
<Td> middle name: </td>
<Td> <input type = "text" name = "middlename"> </td>
</Tr>

<Tr>
<Td> <B> last name: </B> </td>
<Td> <input type = "text" name = "lastname"> </td>
</Tr>

<Tr>
<Td> <B> primary email: </B> </td>
<Td> <input type = "text" name = "email"> </td>
<Td width = "20"> & nbsp; </td>
<Td> secondary email: </td>
<Td> <input type = "text" name = "secondaryemail"> </td>
</Tr>

<Tr>
<Td> company name: </td>
<Td> <input type = "text" name = "companyname"> </td>
</Tr>

<Tr>
<Td> office address: </td>
<Td> <input type = "text" name = "officeaddres1"> </td>
<Td width = "20"> & nbsp; </td>
<Td> home address: </td>
<Td> <input type = "text" name = "homeaddress"> </td>
</Tr>

<Tr>
<Td> </td>
<Td> <input type = "text" name = "officeaddress2"> </td>
</Tr>

<Tr>
<Td> city: </td>
<Td> <input type = "text" name = "officecity"> </td>
<Td width = "20"> & nbsp; </td>
<Td> & nbsp; </td>
<Td> <input type = "text" name = "homecity"> </td>
</Tr>

<Tr>
<Td> state: </td>
<Td> <input type = "text" name = "officestate"> </td>
<Td width = "20"> & nbsp; </td>
<Td> & nbsp; </td>
<Td> <input type = "text" name = "homestate"> </td>
</Tr>

<Tr>
<Td> zip: </td>
<Td> <input type = "text" name = "officezip"> </td>
<Td width = "20"> & nbsp; </td>
<Td> & nbsp; </td>
<Td> <input type = "text" name = "homezip"> </td>
</Tr>

<Tr>
<Td> phone: </td>
<Td> <input type = "text" name = "officephone"> </td>
<Td width = "20"> & nbsp; </td>
<Td> & nbsp; </td>
<Td> <input type = "text" name = "homephone"> </td>
</Tr>

<Tr>
<Td> birthday: </td>
<Td> <input type = "text" name = "birthday"> </td>
</Tr>

<Tr>
<Td> spouse name: </td>
<Td> <input type = "text" name = "spousename"> </td>
<Td width = "20"> & nbsp; </td>
<Td> childrens 'names: </td>
<Td> <input type = "text" name = "children"> </td>
</Tr>

<Tr>
<Td> anniversary: </td>
<Td> <input type = "text" name = "anniversary"> </td>
</Tr>

</Table>

<Br>
<Br>
<Br>
<Input type = "submit" value = "submit">
<Br>
<Br>
<Input type = "reset" value = "clear the form">

</Form>
</Body>
</Html>

<! -- Formerrorcheck. php
<Html>
<Body>
<? Php

$ Errors = 0;
If (! Trim ($ nickname )){
Echo "<br> <B> nickname </B> is required .";
$ Errors ++;
  }
 
If (! Trim ($ firstname )){
Echo "<br> <B> first name </B> is required .";
$ Errors ++;
  }
 
If (! Trim ($ lastname )){
Echo "<br> <B> last name </B> is required .";
$ Errors ++;
  }
 
If (! Trim ($ email )){
Echo "<br> <B> primary email address </B> is required .";
$ Errors ++;
  }

If ($ errors> 0)
Echo "<br> please use your browser's back button ".
"To return to the form, and correct error (s )";
 
?>

</Body>
</Html>


This is a simple verification function.

 

<? Php
Function phone_validate ($ data, $ desc ){
$ Regex = "/^ ([2-9] [0-9] {2 }) [2-9] [0-9] {2}-[0-9] {4}/I ";
If (preg_match ($ regex, $ data )! = 1 ){
Return "the '$ desc' field isn' t valid! ";
        }
Return true;
    }
?>
 

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.