PHP
1 min read

Validate an E-Mail Address with PHP, complete script

This tutorial will teach you how to validate a e-mail id using regular expression to control email Spam. In this tutorial I used ternary operator to filter the values coming from the input box and avoid errors.Complete Coding is here  <?php $email=(isset($_POST[’email’]))?trim($_POST[’email’]):”; function verify($email){ if(!preg_match(‘/^[_A-z0-9-]+((.|+)[_A-z0-9-]+)*@[A-z0-9-]+(.[A-z0-9-]+)*(.[A-z]{2,4})$/’,$email)){ return false; } else { return $email; } } if(isset($_POST[‘submit’])){ […]