PHP filter validation|How to use filter validation in PHP 2021 |
PHP filter validatation|How to use filter validation
Filter Validation in PHP: Validation means to check the input data by the user is in the incorrect format or not. filter_var() is a predefined function that is used to provide validation.
Form Handling
filter_var(): A filter_var function has two parameters variable or data and keyword.
It is used to provide validation on email, URL, IP address, integer, etc.
Validation on Integer: A filter_var() can be used to check given data is an integer or not. FILTER_VALIDATE_INT keyword is used to validate int.
File Handling in PHP
How to use integer value filter validate in php?
<?php if (filter_var($int, FILTER_VALIDATE_INT) ==
true) { echo("integer value is valid"); } else { echo("integer value is not valid"); } ?> *****OUTPUT***** integer value is valid |
How to use integer value filter validate in php?
<?php if (filter_var($int, FILTER_VALIDATE_INT) ==
true) { echo("integer value is valid"); } else { echo("integer value is not valid"); } ?> *****OUTPUT***** integer value is not valid |
Validation
on Email: A filter_var() can
be used to check given email is valid or not. FILTER_VALIDATE_EMAIL keyword is used to validate email. In email @ and dot(.) are
compulsory.
How to use email value filter validate in php?
<?php $email = "icoderweb@gmail.com"; if (filter_var($email, FILTER_VALIDATE_EMAIL)
== true) { echo("email is valid"); } else { echo("email is not valid"); } ?> *****OUTPUT***** email is valid |
How to use email value filter validate in php?
<!DOCTYPE html> <html> <body> <?php $email = "icoderweb@gmail.com"; $email = filter_var($email, FILTER_SANITIZE_EMAIL); if (!filter_var($email, FILTER_VALIDATE_EMAIL) === false) { echo("$email is a valid email address"); } else { echo("$email is not a valid email address"); } ?> </body> </html> *****OUTPUT***** icoderweb@gmail.com is a valid email address |
Validation
on URL: A filter_var() can
be used to check given URL is valid or not.
FILTER_VALIDATE_URL keyword is used to validate the URL.
How to use url value filter validate in php?
<!DOCTYPE html> <html> <body> <?php $url = "https://www.icoderweb.in/"; $url = filter_var($url, FILTER_SANITIZE_URL); if (!filter_var($url, FILTER_VALIDATE_URL) === false) { echo("$url is a valid URL"); } else { echo("$url is not a valid URL"); } ?> </body> </html> *****OUTPUT***** https://www.icoderweb.in/ is a valid URL |
How to use url value filter validate in php?
<?php $url = "https:www.icoderweb.in"; if (filter_var($url, FILTER_VALIDATE_URL) ==
true) { echo("URL is valid"); } else { echo("URL is not valid"); } ?> *****OUTPUT***** URL is not valid |
Validation on IP address: A filter_var() can be used to check given IP address is valid or not. FILTER_VALIDATE_IP keyword is used to validate IP addresses.
How to use ip address value filter validate in php?
<?php $ip = "127.0.0.1"; if (filter_var($ip, FILTER_VALIDATE_IP) ==
true) { echo("Local Host IP is valid"); } else { echo("Local Host IP is not valid"); } ?> *****OUTPUT***** Local Host IP is valid |
How to use ip address value filter validate in php?
<?php $ip = "127.0.1"; if (filter_var($ip, FILTER_VALIDATE_IP) ==
true) { echo("Local Host IP is valid"); } else { echo("Local Host IP is not valid"); } ?> *****OUTPUT***** Local Host IP is not valid |