ddd
  1. /**
  2. * Verification class
  3. *
  4. * @lastmodify 2014-5-16
  5. * @author jy625
  6. */
  7. class VerifyAction{
  8. /**
  9. * Whether it is a null value
  10. */
  11. public static function isEmpty($str){
  12. $str = trim($str);
  13. return !empty($str) ? true : false;
  14. }
  15. /**
  16. * Number verification
  17. * param:$flag: whether int is an integer and float is a floating point type
  18. */
  19. public static function isNum($str,$flag = 'float'){
  20. if(!self::isEmpty($str)) return false;
  21. if(strtolower($flag) == 'int'){
  22. return ((string)(int)$str === (string)$str) ? true : false;
  23. }else{
  24. return ((string)(float)$str === (string)$str) ? true : false;
  25. }
  26. }
  27. /**
  28. * Name matching, such as user name, directory name, etc.
  29. * @param:string $str The string to be matched
  30. * @param:$chinese Whether to support Chinese, supported by default. If it is matching file names, it is recommended to turn this off ( false)
  31. * @param:$charset encoding (default utf-8, supports gb2312)
  32. */
  33. public static function isName($str,$chinese = true,$charset = 'utf-8'){
  34. if(!self::isEmpty($str)) return false;
  35. if($chinese){
  36. $match = (strtolower($charset) == 'gb2312') ? "/^[".chr(0xa1)."-".chr(0xff)."A-Za-z0-9_-]+$/" : "/^[x{4e00}-x{9fa5}A-Za-z0-9_]+$/u";
  37. }else{
  38. $match = '/^[A-za-z0-9_-]+$/';
  39. }
  40. return preg_match($match,$str) ? true : false;
  41. }
  42. /**
  43. * Email verification
  44. */
  45. public static function isEmail($str){
  46. if(!self::isEmpty($str)) return false;
  47. return preg_match("/([a-z0-9]*[-_.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[.][a-z]{2,3}([.][a-z]{2})?/i",$str) ? true : false;
  48. }
  49. //手机号码验证
  50. public static function isMobile($str){
  51. $exp = "/^13[0-9]程序猿笑话[0-9]{8}$|15[012356789]程序猿笑话[0-9]{8}$|18[012356789]程序猿笑话[0-9]{8}$|14[57]程序猿笑话[0-9]$/";
  52. if(preg_match($exp,$str)){
  53. return true;
  54. }else{
  55. return false;
  56. }
  57. }
  58. /**
  59. *URL verification, pure URL format, does not support IP verification
  60. */
  61. public static function isUrl($str){
  62. if(!self::isEmpty($str)) return false;
  63. return preg_match('#(http|https|ftp|ftps)://([w-]+.)+[w-]+(/[w-./?%&=]*)?#i',$str) ? true : false;
  64. }
  65. /**
  66. * Verify Chinese
  67. * @param:string $str The string to be matched
  68. * @param:$charset encoding (default utf-8, support gb2312)
  69. */
  70. public static function isChinese($str,$charset = 'utf-8'){
  71. if(!self::isEmpty($str)) return false;
  72. $match = (strtolower($charset) == 'gb2312') ? "/^[".chr(0xa1)."-".chr(0xff)."]+$/"
  73. : "/^[x{4e00}-x{9fa5}]+$/u";
  74. return preg_match($match,$str) ? true : false;
  75. }
  76. /**
  77. *UTF-8 validation
  78. */
  79. public static function isUtf8($str){
  80. if(!self::isEmpty($str)) return false;
  81. return (preg_match("/^([".chr(228)."-".chr(233)."]程序猿笑话[".chr(128)."-".chr(191)."]程序猿笑话[".chr(128)."-".chr(191)."]程序猿笑话)程序猿笑话/",$word)
  82. == true || preg_match("/([".chr(228)."-".chr(233)."]程序猿笑话[".chr(128)."-".chr(191)."]程序猿笑话[".chr(128)."-".chr(191)."]程序猿笑话)程序猿笑话$/",$word)
  83. == true || preg_match("/([".chr(228)."-".chr(233)."]程序猿笑话[".chr(128)."-".chr(191)."]程序猿笑话[".chr(128)."-".chr(191)."]程序猿笑话){2,}/",$word)
  84. == true) ? true : false;
  85. }
  86. /**
  87. * Verification length
  88. * @param: string $str
  89. * @param: int $type (method, default min <= $str <= max)
  90. * @param: int $min, minimum value; $max, Maximum value;
  91. * @param: string $charset character
  92. */
  93. public static function length($str,$type=3,$min=0,$max=0,$charset = 'utf-8'){
  94. if(!self::isEmpty($str)) return false;
  95. $len = mb_strlen($str,$charset);
  96. switch($type){
  97. case 1: //只匹配最小值
  98. return ($len >= $min) ? true : false;
  99. break;
  100. case 2: //只匹配最大值
  101. return ($max >= $len) ? true : false;
  102. break;
  103. default: //min <= $str <= max
  104. return (($min <= $len) && ($len <= $max)) ? true : false;
  105. }
  106. }
  107. /**
  108. * Verification password
  109. * @param string $value
  110. * @param int $length
  111. * @return boolean
  112. */
  113. public static function isPWD($value,$minLen=6,$maxLen=16){
  114. $match='/^[\~!@#$%^&*()-_=+|{}[],.?/:;'"dw]{'.$minLen.','.$maxLen.'}$/';
  115. $v = trim($value);
  116. if(empty($v))
  117. return false;
  118. return preg_match($match,$v);
  119. }
  120. /**
  121. * Verify username
  122. * @param string $value
  123. * @param int $length
  124. * @return boolean
  125. */
  126. public static function isNames($value, $minLen=2, $maxLen=16, $charset='ALL'){
  127. if(empty($value))
  128. return false;
  129. switch($charset){
  130. case 'EN': $match = '/^[_wd]{'.$minLen.','.$maxLen.'}$/iu';
  131. break;
  132. case 'CN':$match = '/^[_x{4e00}-x{9fa5}d]{'.$minLen.','.$maxLen.'}$/iu';
  133. break;
  134. default:$match = '/^[_wdx{4e00}-x{9fa5}]{'.$minLen.','.$maxLen.'}$/iu';
  135. }
  136. return preg_match($match,$value);
  137. }
  138. /**
  139. * Verification email
  140. * @param string $value
  141. */
  142. public static function checkZip($str){
  143. if(strlen($str)!=6){
  144. return false;
  145. }
  146. if(substr($str,0,1)==0){
  147. return false;
  148. }
  149. return true;
  150. }
  151. /**
  152. * Match date
  153. * @param string $value
  154. */
  155. public static function checkDate($str){
  156. $dateArr = explode("-", $str);
  157. if (is_numeric($dateArr[0]) && is_numeric($dateArr[1]) && is_numeric($dateArr[2])) {
  158. if (($dateArr[0] >= 1000 && $timeArr[0] <= 10000) && ($dateArr[1] >= 0 && $dateArr[1] <= 12) && ($dateArr[2] >= 0 && $dateArr[2] <= 31))
  159. return true;
  160. else
  161. return false;
  162. }
  163. return false;
  164. }
  165. /**
  166. * Matching time
  167. * @param string $value
  168. */
  169. public static function checkTime($str){
  170. $timeArr = explode(":", $str);
  171. if (is_numeric($timeArr[0]) && is_numeric($timeArr[1]) && is_numeric($timeArr[2])) {
  172. if (($timeArr[0] >= 0 && $timeArr[0] <= 23) && ($timeArr[1] >= 0 && $timeArr[1] <= 59) && ($timeArr[2] >= 0 && $timeArr[2] <= 59))
  173. return true;
  174. else
  175. return false;
  176. }
  177. return false;
  178. }
  179. }
复制代码
  1. dddd
复制代码


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

11 Best PHP URL Shortener Scripts (Free and Premium) 11 Best PHP URL Shortener Scripts (Free and Premium) Mar 03, 2025 am 10:49 AM

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Working with Flash Session Data in Laravel Working with Flash Session Data in Laravel Mar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

Build a React App With a Laravel Back End: Part 2, React Build a React App With a Laravel Back End: Part 2, React Mar 04, 2025 am 09:33 AM

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Simplified HTTP Response Mocking in Laravel Tests Simplified HTTP Response Mocking in Laravel Tests Mar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Announcement of 2025 PHP Situation Survey Announcement of 2025 PHP Situation Survey Mar 03, 2025 pm 04:20 PM

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

Notifications in Laravel Notifications in Laravel Mar 04, 2025 am 09:22 AM

In this article, we're going to explore the notification system in the Laravel web framework. The notification system in Laravel allows you to send notifications to users over different channels. Today, we'll discuss how you can send notifications ov

See all articles