使用PHP验证打开购物车中的电话号码

发布于 2025-02-04 22:56:09 字数 704 浏览 3 评论 0原文

OpenCart 3

<div class="form-group ">
   <label class="col-sm-2 control-label" for="input-name"> another telephone</label>
   <div class="col-sm-10">
      <input type="text" name="another_telephone" value="{{another_telephone}}" class="form-control" placeholder="another telephone">
   </div>
</div>

我在供应商商店表单中添加了自定义字段'另一个telephone'。 这是接受字母,数字和符号。

问题:我想验证我的字段是否有效电话号码。

附加图像:文本字段&gt;另一个电话

opencart 3

<div class="form-group ">
   <label class="col-sm-2 control-label" for="input-name"> another telephone</label>
   <div class="col-sm-10">
      <input type="text" name="another_telephone" value="{{another_telephone}}" class="form-control" placeholder="another telephone">
   </div>
</div>

I have added a custom field 'another-telephone' in vendor store form.
which is accepting alphabets, numbers and symbols.

Question : I want to validate my field for valid phone number .

Image Attached : text field > another telephone

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

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

发布评论

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

评论(1

乖不如嘢 2025-02-11 22:56:09

也许我无法正确理解您的问题,但是如果您需要更改另一个电话,该手机是字母/数字模式2(a,b,c)3(d,e,f) 4(g,h,i)5(j,k,l)6(m,n,0)7(p,q,r,s)8(t,u,v)9(w,w,x,y, z)您可以尝试以下操作:

$another_phone = 'holidays1';
$alias_array = array(
    '0' => ['0'],
    '1' => ['1'],
    '2' => ['A','B','C'],
    '3' => ['D','E','F'],
    '4' => ['G','H','I'],
    '5' => ['J','K','L'],
    '6' => ['M','N','O'],
    '7' => ['P','Q','R','S'],
    '8' => ['T','U','V'],
    '9' => ['W','X','Y','Z']);
    
$phone_in_letters = strtoupper($another_phone);
//creating an array
$phone_in_letters_array = str_split($phone_in_letters );

$phone_array = [];
foreach($phone_in_letters_array as $val) {
    foreach ($alias_array as $key => $letters) {
        if (in_array($val, $letters)) {
            $phone_array[] = $key;
        }
    }
}

print_r(implode($phone_array));

Maybe i do not understand correctly your question, but if you need to change your another-phone which is in letters to the numbers by Letters/numbers pattern 2(A,B,C) 3(D,E,F) 4(G,H,I) 5(J,K,L) 6(M,N,0) 7(P,Q,R,S) 8(T,U,V) 9(W,X,Y,Z) you can try this:

$another_phone = 'holidays1';
$alias_array = array(
    '0' => ['0'],
    '1' => ['1'],
    '2' => ['A','B','C'],
    '3' => ['D','E','F'],
    '4' => ['G','H','I'],
    '5' => ['J','K','L'],
    '6' => ['M','N','O'],
    '7' => ['P','Q','R','S'],
    '8' => ['T','U','V'],
    '9' => ['W','X','Y','Z']);
    
$phone_in_letters = strtoupper($another_phone);
//creating an array
$phone_in_letters_array = str_split($phone_in_letters );

$phone_array = [];
foreach($phone_in_letters_array as $val) {
    foreach ($alias_array as $key => $letters) {
        if (in_array($val, $letters)) {
            $phone_array[] = $key;
        }
    }
}

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