checkChajian.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * 字符检查插件
  4. */
  5. class checkChajian extends Chajian{
  6. /**
  7. * 是否为邮箱
  8. */
  9. public function isemail($str)
  10. {
  11. if(isempt($str))return false;
  12. return filter_var($str, FILTER_VALIDATE_EMAIL);
  13. }
  14. /**
  15. * 是否为手机号
  16. */
  17. public function ismobile($str)
  18. {
  19. if(isempt($str))return false;
  20. if(!is_numeric($str) || strlen($str)<5)return false;
  21. return true;
  22. }
  23. /**
  24. * 判断是否为国内手机号
  25. */
  26. public function iscnmobile($str)
  27. {
  28. if(isempt($str))return false;
  29. if(!is_numeric($str) || strlen($str)!=11)return false;
  30. if(!preg_match("/1[3458769]{1}\d{9}$/", $str))return false;
  31. return true;
  32. }
  33. /**
  34. * 是否有中文
  35. */
  36. public function isincn($str)
  37. {
  38. return preg_match("/[\x7f-\xff]/", $str);
  39. }
  40. //是否整个的英文a-z,0-9
  41. public function iszgen($str)
  42. {
  43. if(isempt($str))return false;
  44. if($this->isincn($str)){
  45. return false;
  46. }
  47. return true;
  48. }
  49. //返回字符串编码
  50. public function getencode($str)
  51. {
  52. $encode = mb_detect_encoding($str, array('ASCII','UTF-8','GB2312','GBK','BIG5'));
  53. $encode = strtolower($encode);
  54. return $encode;
  55. }
  56. /**
  57. * 是否为数字
  58. */
  59. public function isnumber($str)
  60. {
  61. if(isempt($str))return false;
  62. return is_numeric($str);
  63. }
  64. /**
  65. * 字符是否包含数字
  66. */
  67. public function isinnumber($str)
  68. {
  69. return preg_match("/[0-9]/", $str);
  70. }
  71. /**
  72. * 是否为日期
  73. */
  74. public function isdate($str)
  75. {
  76. return preg_match("/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/", $str);
  77. }
  78. /**
  79. * 是否为日期时间
  80. */
  81. public function isdatetime($str)
  82. {
  83. return preg_match("/^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$/", $str);
  84. }
  85. /**
  86. * 是否为月份
  87. */
  88. public function ismonth($str)
  89. {
  90. return preg_match("/^([0-9]{4})-([0-9]{2})$/", $str);
  91. }
  92. /**
  93. * 过滤字母,只留数字
  94. */
  95. public function onlynumber($str)
  96. {
  97. return preg_replace('/[a-zA-Z]/','', $str);
  98. }
  99. /**
  100. * 替换空格
  101. */
  102. public function replacekg($str)
  103. {
  104. $str = preg_replace('/\s*/', '', $str);
  105. $qian = array(" "," ","\t","\n","\r");
  106. return str_replace($qian, '', $str);
  107. }
  108. }
粤ICP备19079148号