PHP / * My data verification class * / class checker {// function definition var $ array_data = ""; // To verify the array data var $ var_key = "; // The data of the current to verify the key to Key VAR $ VAR_VALUE = ""; // The value of the current to verify VAR $ is_empty = ""; // The value to verify can be empty VAR $ array_info = ""; // Tips Information Collect Var $ array_errors = array ( ); // error message collection
// ---------------------> Constructor <------------ Function Checker ($ DATE) {$ this-> Array_data = $ date;}
// ---------------------> Data inspection function <------------ Function Check ($ array_datas) {foreach $ array_datas as $ value_key => $ value_v) {$ TEMP1 = EXPLODE ('|', $ value_v); if ($ TEMP1 [0] == "i_empty" and empty ($ this-> array_data [$ value_key])) {;} Else {foreach ($ TEMP1 AS $ TEMP_KEY => $ VALUE_CON) {// $ data_temp = $ this-> array_data; // var_dump ($ data_temp ['birthday'); // echo "-". $ Value_Key. "-
"; $ this-> var_key = $ value_key; $ this-> var_value = $ this-> array_data [$ value_key]; $ TEMP2 = EXPLODE (':', $ value_con); switch; switch (Count ($ TEMP2)) {Case 0: $ this-> array_errors [$ this-> var_key] = "This value verifies not exist"; Break; case 1: // If the user does not specify a verification action IF (EMPTY ($ THIS-> array_errors [$ this-> var_key] = "Verification request for this value does not exist"; Break;} else {$ this -> $ TEMP2 [0] (); / / If the return value is not, you don't have to perform the next step. ($ TEMP2 [0) -> $ TEMP2 [1]); Break; Case 3: $ THIS -> $ TEMP2 [0] ($ TEMP2 [1], $ TEMP2 [2]); Break;}}}}} function i_empty ()} function i_empty () {$ this-> is_empty = 1; // This value is not used, just explains the value to verify can be empty Value}
// Date data, email address, floating point data, integer, IP address, string, maximum, minimum, string length, domain name, URL / / ------------- -----> Date Verification -------------------- Function I_Date () {// Convention Format: 2000-02-01 or: 2000-5-4 IF (! EREGI ("^ [1-9] [0-9] - [0-9] - [0-9] $", $ this-> var_value) ) {$ This-> var_key] = "Date format error"; Return False;} $ TIME = STRTOTIME ($ this-> var_value); if ($ TIME === -1) {$ THIS -> array_errors [$ this-> var_key] = "Date Format Error"; Return False; $ TIME_E = EXPLODE ('-', $ this-> var_value); $ TIME_EX = EXPLODE ('-', DATE ('ym -D ', $ time)); for ($ I = 0; $ I
"; // Echo $ this-> var_value; Return True;} // --------------------> Floating point verification -------------------- Function i_float () {// if (! is_float ($ this-> var_value)) IF (! EREG ("^ [1-9] [0-9]? /. ([0-9]) $", $ this-> var_value)) $ this-> array_errors [$ this->
Var_key] = "This is not a decimal";} // --------------------> String verification ------------- ------- Function I_String () {i (Empty ($ this-> var_value)) // Allow empty return true; if (! is_string ($ this-> var_value) $ this-> array_errors [$ this-> var_key] = "This is not a string"; return true;} // -------------------> String length verification ----- --------------- Function LEN ($ MINV, $ Maxv = -1) {$ LEN = Strlen ($ this-> var_value); if ($ g == 0) {$ this-> array_errors [$ this-> var_key] = "No null value"; Return False;} IF ($ LEN <$ minv) {$ this-> array_errors [$ this-> var_key] = "input "Return false;} if ($ maxv! = -1) {IF ($ LEN> $ maxv) {$ this-> array_errors [$ this-> var_key] =" Enter the string too long "; Return False;}} Return True;} // --------------------> Integer verification ----------------- --- Function i_int () {ix (! EREG ("^ [0-9] * $", $ this-> var_value)) $ this-> array_errors [$ this-> var_key] = "This is not an integer" ;} // --------------------> IP address verification ------------------- Function I_IP () {if ("G (" ^ [0-9] {1, 3} /. [0-9] {1,3} /. [0-9] {1,3} /. [0-9 ] {1,3} $ ", $ THIS -> var_value)) {$ this-> array_errors [$ this-> var_key] = "Error IP address";} else {// Each is not greater than 255 $ array_temp = preg_split ("//./", worth worth?" -> var_value; foreach ($ array_temp as $ ip_value) {if ((int) $ ip_value> 255) $ this-> array_errors [$ this-> var_key] = "Error IP address";}}} Return True;} // --------------------> Maximum validation ------------------ Function I_max ($ Maxv) {if ($ this-> var_value> = $ maxv) {$ this-> array_errors [$ this-> var_key] = "data value is too big"; return true;} Return true;} // -------- ---------------->
Minimum verification ------------------- Function I_MIN ($ MINV) {IF ($ this-> var_value <= $ minv) {$ this-> array_errors [$ THIS-> var_key] = "Data value is too small"; return false;} Return True;} // ------------------> Domain name verification ---- ---------------- Function I_DOMAIN () {if (! EREGI ("^ @ ([0-9A-z / -_] /.) [0-9A- Z / -_】 $ ", $ this-> var_value)) $ this-> array_errors [$ this-> var_key] =" Error Domain Name "; Return EREGI (" @ (@ ([0-9A-z / - _] /.) [0-9A-z / -_] $ ", $ this-> var_value);} // ------------------- -> URL verification ------------------- function i_url () {if (! EREGI ('^ (http: // | https: //) {1} [A-Z0-9] (/. [A-Z0-9] ) $ ', $ this-> var_value)) $ this-> array_errors [$ this-> var_key] = "Error Web Address" Return True;} // --------------------> Custom Regular check ----------------- --- Function Check_own ($ user_pattern) {// custom verification. Error returning False, matching back 1, mismatch returns 0 $ TEMPVAR = preg_match ($ user_pattern, $ this-> var_value); if ($ TEMPVAR! = 1) $ this-> array_errors [$ this-> var_key] = "data Not legal ";} ################## THE END #################### ##############}