Wechat.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace app\common\validate;
  3. use think\Validate;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 验证器
  10. */
  11. class Wechat extends Validate
  12. {
  13. protected $rule = [
  14. 'name' => 'require',
  15. 'sort' => 'number',
  16. 'type' => 'require',
  17. 'value' => 'checkValue:1'
  18. ];
  19. protected $message = [
  20. 'name.require' => '菜单名称不能为空',
  21. 'sort.number' => '排序只能为数字',
  22. 'type.require' => '类型不能为空',
  23. 'value.checkValue' => 'URL地址错误'
  24. ];
  25. protected $scene = [
  26. 'menu_add' => ['name', 'sort', 'type', 'value'],
  27. 'menu_edit' => ['name', 'sort', 'type', 'value'],
  28. ];
  29. protected function checkValue($value)
  30. {
  31. if (input('post.menu_type') == 'view') {
  32. if (empty($value)) {
  33. return 'URL地址格式不能为空';
  34. }
  35. if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $value)) {
  36. return "URL地址格式不正确";
  37. }
  38. }
  39. return true;
  40. }
  41. }