PHP encapsulated Form Validation class complete instance _php tips

Source: Internet
Author: User
Tags php database php introduction

This example describes the form validation classes that are encapsulated in PHP. Share to everyone for your reference, specific as follows:

<?php
//Package a form verification class//
Chinese verification, mailbox verification, telephone number, mobile phone, QQ, ID card, (composed of letters, numbers, underscores, can not start with a number)
header (' content-type:text/ Html;charset=utf-8 ');
Class form{
 ///Chinese authentication method
 //parameter: $STR, $num 1, $num 2
 //return value: Matching number of successful matches returned
 /Public function Checkchina ($str, $num 1, $num 2= ') {
  //regular
 $reg = '/^[\x{4e00}-\x{9fa5}]{'. $num 1. ', '. $num 2. '} '. ' $/u ';
 Return Preg_match ($reg, $str);
 }
 ///
 Mailbox Verification
 //parameters: $email
 //return value: Matching number of successful matches returned/public
 function Checkemail ($email) {
 // Regular
 $reg = '/^\w+@\w+[.] com|cn|net$/';
 Return Preg_match ($reg, $email);
 }
 ///
 Verify ID
 //parameter $card
 //Return value: Number of matches successfully returned
 * * Public
 function Checkcard ($card) {
 //Regular
 $reg = '/^ (\d{18}|\d{17}x) $/';
 Return Preg_match ($reg, $card);
 }
 ///
 require that the input be composed of numbers, letters, underscores, cannot begin with a number, has a bit limit
 //parameter: $STR, $num 1, $num 2
 //return value: The number
 of matches successfully returned. Public Function Checkstr ($STR, $num 1, $num 2) {
 //regular
 $reg = '/^[a-za-z_]\w{'. ( $num 1-1). ', '. ($num 2-1). '} $/';
 Return Preg_match ($reg, $str);
 }


More about PHP Interested readers can view the site topics: "PHP Design Security Course", "PHP Security Filtering Skills Summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", "PHP basic Grammar Introductory Course", " PHP Operations Office Document Tips summary (including word,excel,access,ppt), "PHP Introduction to Object-oriented Programming", "PHP string (String) Usage Summary", "Php+mysql Database Operations Introductory Tutorial" and " A summary of common PHP database operations tips

I hope this article will help you with the PHP program design.

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.