Wechat.php 1.4 KB

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