4位数字的Laravel请求验证,这也不是重新列出参数

发布于 2025-02-13 11:05:05 字数 113 浏览 0 评论 0原文

我想验证仅适用于4位数字的PIN代码,不需要它。 表示PIN代码仅为4位数字。例如1234、8675,或者如果用户未输入任何数字来输入类型,则用户提交表单。如果用户未输入PIN代码,我想给数据库的默认值1111。

I want to validate a pin code that is just for 4 digits and it should not be required.
means pin code is only 4 digits. like 1234, 8675, or if the user does not enter any digits to Pincode input type let the user submit the form. I want to give the database's default value 1111 if the user doesn't enter the pin code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你是我的挚爱i 2025-02-20 11:05:05

您可以验证允许pinnull的请求(或使用表单请求),否则否则验证它是4位数字。然后,您可以从输入或后备到1111。的默认值获取pin

$request->validate([
    'pin' => ['nullable', 'numeric', 'digits:4'],
]);

$pin = $request->input('pin', '1111');

You can validate the request (or use a form request) that allows pin to be null otherwise validates it is a 4 digit number. You can then get the pin from the input or fallback to the default value of 1111.

$request->validate([
    'pin' => ['nullable', 'numeric', 'digits:4'],
]);

$pin = $request->input('pin', '1111');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文