Problems with Custom Verification in Tp5

for example, the array is like this

$data = [
    [
        "mobile"=> "1",
        "price" => "100.00"
    ],
        [
        "mobile"=> "2",
        "price" => "500.00"
    ],
];

one-dimensional array can be verified directly

  protected $rule = [
    "mobile"=> "require|mobile",
  ]

but now it is a two-dimensional array, and Tp has custom verification. What you want to verify now is that the mobile phone number in the array must have a value and must be a legal mobile phone number, and the amount must be a positive integer or two digits after the decimal point!

Custom validation:

  protected $rule = [
    "mobile"=> "require|array|checkMobile",
  ]
//
protected function checkMobile()
{
  //?
  //Tp mobile require unique!!!!
}
Mar.29,2021

emmm,foreach to call an abstract independent validator, idea. I read the previous TP5 project, which seems to be a check of an one-digit array at most. I hope it will be helpful to you


//
    protected function checkMobile($value)
    {
        -sharp 01:   (value)
        -sharp 02:  mobile
        -sharp 03: 
        -sharp 04: $this->message();
        -sharp 05:   $this->check(,);
        -sharp 06:  false  $this->getError();
        foreach ($value as $item) {
            $data['mobile'] = $item;
            $rules = [
                'mobile' => 'require|mobile',
            ];
            $message = [
                'mobile.require' => '!',
                'mobile.mobile' => '!',
            ];
            if (false === $this->message($message)->check($data, $rules)) {
                return $this->getError();
            } else {
                return true;
            }
        }
    }

when using:

    protected $rule = [
        'mobile' => 'require|checkMobile',
    ];

data is:

$data = [
    [
        'mobile'=> ['1','2'],
    ];
];
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-7b6d42-29b74.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-7b6d42-29b74.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?