How To Validate Email, URL And IP in PHP

I know to most PHP programmers, this isn’t a big deal.

I am going to show us, how to validate Email, URL and IP address using their respective PHP validation function.

It is very important input by users are validated before they are sent for processing. Not validating what users enter can lead to a serious security breach and could make your website susceptible to hackers.

PHP has a large number of filters for validation and sanitation, but we’re only going to see that of the Email, URL and IP address.

Let’s take a look at these validation filters and how they work.

  1. Validating Email
    • Functionfilter_var($value, FILTER_VALIDATE_EMAIL)

  2. Validating URL
    • Functionfilter_var($value, FILTER_VALIDATE_URL)

  3. Validating IP address
    • Functionfilter_var($value, FILTER_VALIDATE_IP)