PHP common Form Validation Class usage example

Source: Internet
Author: User
Tags foreach php programming

This example describes the usage of PHP's common form validation classes. Share to everyone for your reference. Specifically as follows:

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 5, 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 11 9 120 121 122 123 124 125 126 127 128 129 <?php/** * page role: Common form Validation class * Author: Gladly with the wind * qq:276624915/class Class_post {//Verify that the letter/number combination function for the specified length fun_text1 ($num 1, $num 2, $str) {return (Preg_match ("/^[a-za-z0-9]{". $num 1. ",". $num 2. "} $/", $str))? True:false; //Verify that the specified length numeric function fun_text2 ($num 1, $num 2, $str) {return Preg_match ("/^[0-9]{". $num 1. ",". $num 2. "} $/i ", $str))? True:false; //Verify if 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 ID number function Fun_status ($STR) {return Preg_match ('/(^ d]{15}|[ d]{18}| [d] {17}x) $)/', $str) ' True:false; //Verify 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}-))? ((0d{2,3}) |0d{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;Certificate URL address function Fun_url ($STR) {return (Preg_match) ("/^http://[a-za-z0-9]+.[ a-za-z0-9]+[/=?%-&_~ ' @[] ': +!] * ([^<> "]) *$/", $str))? True:false; ///Data warehousing escape special characters incoming values can be string or one-dimensional Array function Data_join (& $data) {if (GET_MAGIC_QUOTES_GPC () = False) {if Is_array ($dat A) {foreach ($data as $k => $v) {$data [$k] = addslashes ($v);} else {$data = Addslashes ($data);}} return $data; }//Database restore special characters incoming values can be string or one/two D array function Data_revert (& $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] = 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 incoming values should be Data_revert () before executing this method for a string or a/two D array, and the form content does not need this restore function data_show (& $data) {if Is_ar Ray ($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]=NL2 BR (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", "<br>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", "<br>n", $data [$k 1]); }} else {$data =nl2br (Htmlspecialchars ($data)); $data =str_replace ("", "", $data); $data =str_replace ("n", "<br>n", $data); return $data; }}?>

I hope this article will help you with your PHP programming.

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.