简体   繁体   中英

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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