Examples of common php form verification usage

Source: Internet
Author: User
Tags php form

Examples of common php form verification usage

This example describes common php form verification usage. Share it with you for your reference. The details are 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

43

44

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

84

85

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

119

120

121

122

123

124

125

126

127

128

129

<? Php

/**

* Page function: common form verification classes

* Author: Happy with the wind

* QQ: 276624915

*/

Class class_post

{

// Verify whether it is a combination of letters and numbers with a specified length

Function fun_text1 ($ num1, $ num2, $ str)

{

Return (preg_match ("/^ [a-zA-Z0-9] {". $ num1. ",". $ num2. "} $/", $ str ))? True: false;

}

// Verify whether it is a number of the specified length

Function fun_text2 ($ num1, $ num2, $ str)

{

Return (preg_match ("/^ [0-9] {". $ num1. ",". $ num2. "} $/I", $ str ))? True: false;

}

// Verify whether the Chinese character is of the specified length

Function fun_font ($ num1, $ num2, $ str)

{

// Preg_match ("/^ [\ xa0-\ xff] {1, 4} $/", $ string );

 

Return (preg_match ("/^ ([\ x81-\ xfe] [\ x40-\ xfe]) {". $ num1 .",". $ num2. "} $/", $ str ))? True: false;

}

// Verify the ID card number

Function fun_status ($ str)

{

Return (preg_match ('/(^ ([\ d] {15} | [\ d] {18} | [\ d] {17} x) $ )/', $ str ))? True: false;

}

// Verify the email 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 the 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 the zip code

Function fun_zip ($ str)

{

Return (preg_match ("/^ [1-9] \ d {5} $/", $ str ))? True: false;

}

// Verify the url

Function fun_url ($ str)

{

Return (preg_match ("/^ http: \ // [A-Za-z0-9] + \. [A-Za-z0-9] + [\/= \? % \-&_~ '@ [\] \': +!] * ([^ <> \ "\"]) * $/", $ Str ))? True: false;

}

// The data warehouse receiving escape special character input value can be a string or a 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 warehouse restore special character input value can be a string or one/two-dimensional array

Function data_revert (& $ data)

{

If (is_array ($ data ))

{

Foreach ($ data as $ k1 => $ v1)

{

If (is_array ($ v1 ))

{

Foreach ($ v1 as $ k2 => $ v2)

{

$ Data [$ k1] [$ k2] = stripslashes ($ v2 );

}

}

Else

{

$ Data [$ k1] = stripslashes ($ v1 );

}

}

}

Else

{

$ Data = stripslashes ($ data );

}

Return $ data;

}

// The data display restoration data format is mainly used for the input value of the content output to be a string or A/two-dimensional array.

// Data_revert () should be performed before this method is executed, and the form content does not need to be restored

Function data_show (& $ data)

{

If (is_array ($ data ))

{

Foreach ($ data as $ k1 => $ v1)

{

If (is_array ($ v1 ))

{

Foreach ($ v1 as $ k2 => $ v2)

{

$ Data [$ k1] [$ k2] = nl2br (htmlspecialchars ($ data [$ k1] [$ k2]);

$ Data [$ k1] [$ k2] = str_replace ("", "", $ data [$ k1] [$ k2]);

$ Data [$ k1] [$ k2] = str_replace ("\ n", "<br> \ n", $ data [$ k1] [$ k2]);

}

}

Else

{

$ Data [$ k1] = nl2br (htmlspecialchars ($ data [$ k1]);

$ Data [$ k1] = str_replace ("", "", $ data [$ k1]);

$ Data [$ k1] = str_replace ("\ n", "<br> \ n", $ data [$ k1]);

}

}

}

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