我已经在laravel 8中构建了带有标记的表单,现在它已经开始工作了。但现在需要添加一个电话号码字段时,用户注册他们的帐户。这是当前代码。
<form method="post" action="{{ route('L4.contestants.store', $organization) }}" enctype="multipart/form-data">
@csrf
<div class="row mb-4 md-3">
<div class="col-12">
<label for="birthdate"> Birthdate </label>
<x-form.input type="date" id="birthdate" name="birthdate" />
</div>
</div><!--/row-->
<div class="row mb-4 md-3">
<div class="col-12">
<label for="phone"> Phone Number </label>
<x-form.input type="tel" id="phone" name="phone" />
</div>
</div><!--/row-->
<hr>
<x-form.buttons submit-name="Add" :cancel-url="route('L4.contestants.index', $organization)" />
</form>现在,它正在工作,但我需要使用与国家和验证。由于不需要改变别人,所以我们应该使用x-form标签。请帮帮我。谢谢。
发布于 2022-04-13 11:29:23
我建议您使用Laravel-电话包,至少在我看来,这是验证和格式化电话号码的最干净的方法。
$request->validate([
'phone' => [
'required',
Rule::phone()->detect()->country('ES'),
],
]);若要格式化电话号码,例如,要具有保存到数据库中的一致表单或与之进行比较,请使用:
PhoneNumber::make('666666666', 'ES')->formatE164(); // returns +34666666666https://stackoverflow.com/questions/71856604
复制相似问题