Search code examples
phpemail-validationphone-numberfilter-var

php email sanitize and validation not working


I have this php code

if(filter_var($_POST['username'], FILTER_SANITIZE_EMAIL) !== false && filter_var($_POST['username'], FILTER_VALIDATE_EMAIL) !== false) {
                echo 'it is mail';
            }else{
                echo 'is is phone';
            }

when I'm sending the post data like this

example@bla.com

it is writing it is mail. but when I'm sending the data like this

+995216846121

then it is writing also that it is mail

what is wrong? please help me.

I need to check if client add mail or phone number.


Solution

  • I added one more check with is_numeric() and now everithing is good. thenk you All!!!