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.