Validate value as an e-mail address in PHP

Description

The following code shows how to validate value as an e-mail address.

Example


// w w w  .  j av a2 s . co  m
<?php
    $email = "someone@exa mple.com";

    if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
        echo "E-mail is not valid";
    }else{
        echo "E-mail is valid";
    }
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Data Types »




Array
Array Associative
Array Util
ArrayObject
Data Types
Date
Date Format
DateTime
Number
String
String Escape
String Filter
String HTML
String Type
Timezone