简体   繁体   English

如何在php中检查一个数字的字符串是否有10个字符

[英]how to check if a string of a number has 10 characters in php

I am struggeling at implementing a check on a textbox.我正在努力对文本框进行检查。

I want to check if the phone number has a length of 10 characters, contains my country base number and if it is actually a numerical value.我想检查电话号码的长度是否为 10 个字符,是否包含我的国家基数以及它是否实际上是一个数值。

i only know how to check if it is a number.我只知道如何检查它是否是一个数字。

                    if(ctype_digit($telefon) && ctype_digit($telefon)=="10"){
                          ...
                        
                    } else {
                        echo "Invalid phone number";
                    }
            

Using PHP's 'strlen($string)' function would count every character including any format notations使用 PHP 的 'strlen($string)' 函数将计算每个字符,包括任何格式符号

https://www.w3schools.com/PHP/func_string_strlen.asp https://www.w3schools.com/PHP/func_string_strlen.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM