PHP Common Forms Validation Class usage instance, PHP form validation Example _php tutorial

Source: Internet
Author: User
Tags php form php form validation

PHP Common Forms Validation Class usage instance, PHP form validation instance

The example in this paper describes the use of PHP common forms validation class. Share to everyone for your reference. Specific as follows:

<?php/*** page function: Common Forms Validation Class * Author: Gladly with the wind * Qq:276624915*/class class_post{//Verify that the letter/number combination function Fun_text1 is the specified length ($num 1,$ Num2, $str) {Return (Preg_match ("/^[a-za-z0-9]{". $num 1. ",". $num 2. "} $/", $str))? True:false;} Verifies whether the numeric function fun_text2 for the specified length ($num 1, $num 2, $str) {return (Preg_match ("/^[0-9]{". $num 1. ",". $num 2. "} $/i ", $str))? True:false;}   Verifies whether the specified length kanji function fun_font ($num 1, $num 2, $STR) {//Preg_match ("/^[\xa0-\xff]{1,4}$/", $string); Return (Preg_match ("/^ ([\x81-\xfe][\x40-\xfe]) {". $num 1. ",". $num 2. "} $/", $str))? True:false;} Verify the ID number function Fun_status ($STR) {return (Preg_match ('/(^ [\d]{15}|[ \d]{18}| [\d] {17}x) $)/', $str))? True:false;} Verify the mail address function fun_email ($STR) {return (Preg_match ('/^[_\.0-9a-z-]+@ (' 0-9a-z][0-9a-z-]+\.) +[a-z]{2,4}$/', $str))? True:false;} Verify phone number function Fun_phone ($STR) {return (Preg_match ("/^ (\d{3}\) | ( \d{3}\-))? (\ (0\d{2,3}\) |0\d{2,3}-)? [1-9]\d{6,7}$/", $str))? True:false;} Verify Zip function fun_zip ($str) {return (Preg_match ("/^[1-9]\d{5}$/", $str))? True:false;} Verify URL address function Fun_url ($str) {return (Preg_match ("/^http:\/\/[a-za-z0-9]+\.[ a-za-z0-9]+[\/=\?%\ -&_~ ' @[\]\ ': +!] * ([^<>\ "]) *$/", $str))? True:false;} Data inbound Escape special character passed in value can be a string or one-dimensional array function Data_join (& $data) {if (GET_MAGIC_QUOTES_GPC () = False) {if (Is_array ($data   ) {foreach ($data as $k = + $v) {$data [$k] = addslashes ($v);  }} else {$data = Addslashes ($data); }} Return $data;} Data out-of-Library restore special character incoming value can be a string or a/two-D array function Data_revert (& $data) {if (Is_array ($data)) {foreach ($data as $k 1 = $   V1) {if (Is_array ($v 1)) {foreach ($v 1 as $k 2 = $v 2) {$data [$k 1][$k 2] = stripslashes ($v 2);   }} else {$data [$k 1] = stripslashes ($v 1);  }}}} else {$data = Stripslashes ($data); } Return $data;} Data display the Restore data format is primarily used for content output the incoming value can be a string or a/two-dimensional array//Data_revert () should precede this method, the form contents do not need this restore function data_show (& $data) {if (Is_array ( $data) {foreach ($data as $k 1 = $v 1) {if (Is_array ($v 1)) {foreach ($v 1 as $k 2 + $v 2) {$data [$k 1[$k 2]=nl2br (Htmlspecialchars ($data [$k 1][$k 2]);   $data [$k 1][$k 2]=str_replace ("", "", $data [$k 1][$k 2]); $data [$k 1][$k 2]=str_replace ("\ n", "
\ n ", $data [$k 1][$k 2]); }} else {$data [$k 1]=nl2br (Htmlspecialchars ($data [$k 1]); $data [$k 1]=str_replace ("", "", $data [$k 1]); $data [$k 1]=str_replace ("\ n", "
\ n ", $data [$k 1]); }}}} else {$data =nl2br (Htmlspecialchars ($data)); $data =str_replace ("", "", $data); $data =str_replace ("\ n", "
\ n ", $data); } Return $data;}}? >

I hope this article is helpful to everyone's PHP programming. true techarticle PHP Common Forms Validation class usages, PHP form Validation Example This article describes the PHP common forms validation class usage. Share to everyone for your reference. Specifically as follows: php/*** page action ...

  • 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: 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.