PHP Common Forms Validation Class usage Example _php tutorial

Source: Internet
Author: User

PHP Common Forms Validation Class usage instance


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

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21st

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

/**

* Page function: Common Forms Validation Class

* Author: Gladly with the wind

* qq:276624915

*/

Class Class_post

{

Verifies whether a combination of letters/numbers of a specified length

function Fun_text1 ($num 1, $num 2, $STR)

{

Return (Preg_match ("/^[a-za-z0-9]{". $num 1. ",". $num 2. "} $/", $str))? True:false;

}

Verifies whether a number is a specified length

function Fun_text2 ($num 1, $num 2, $STR)

{

Return (Preg_match ("/^[0-9]{". $num 1. ",". $num 2. "} $/i ", $str))? True:false;

}

Verifies whether the specified length is a Chinese character

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

function Fun_zip ($STR)

{

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

}

Verify the 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 incoming 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 out-of-Library restore special characters incoming values can be strings or one/two-dimensional arrays

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 can be strings or one/two-dimensional arrays

You should data_revert () before executing this method, and the contents of the form need not be restored

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.

http://www.bkjia.com/PHPjc/1018372.html www.bkjia.com true http://www.bkjia.com/PHPjc/1018372.html techarticle PHP Common Forms validation class usages examples in this article describe the PHP common forms validation class usage. Share to everyone for your reference. Specific as follows:? 1 2 3 4 5 6 7 8 9 Ten ...

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