-4

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";
                    }
            
RoyB
  • 3,104
  • 1
  • 16
  • 37
  • A phone number may not be just 10 chars as it could contain `+ 41 79` or `(21)`. Use a regex to do that instead. See the topic here https://stackoverflow.com/questions/123559/how-to-validate-phone-numbers-using-regex – Patrick Janser May 09 '22 at 14:02
  • `^\d{10}$` would be 10 numbers. You should make sure you make it clear that is the only valid format. You also are open to SQL injections with this code. – user3783243 May 09 '22 at 14:30
  • **Warning:** You are wide open to [SQL Injections](https://php.net/manual/en/security.database.sql-injection.php) and should use parameterized **prepared statements** instead of manually building your queries. They are provided by [PDO](https://php.net/manual/pdo.prepared-statements.php) or by [MySQLi](https://php.net/manual/mysqli.quickstart.prepared-statements.php). Never trust any kind of input! Even when your queries are executed only by trusted users, [you are still in risk of corrupting your data](http://bobby-tables.com/). [Escaping is not enough!](https://stackoverflow.com/q/32391315) – Dharman May 09 '22 at 14:37
  • I have removed some code that did not contribute to the problem. Please, next time write down a minimal reproducible example, and use only english in your code. Also, use punctuation in your question to make it readable. – RoyB May 16 '22 at 08:25

1 Answers1

0

Using PHP's 'strlen($string)' function would count every character including any format notations

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

MisterG13
  • 110
  • 10