Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to eregi() in php [duplicate]

Tags:

php

eregi

So, i was using eregi in my mail script, but as of lately, i get the error that the function is deprecated.

So, what is the easiest way to replace the following bit of code:

if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email'])))?

Any help is appreciated :)

like image 205
idjuradj Avatar asked Feb 23 '13 22:02

idjuradj


1 Answers

 if (!preg_match("/^[A-Z0-9.%-]+@[A-Z0-9.%-]+.[A-Z]{2,4}$/", trim($_POST['email'])))

Using preg_match.

Because ereg_* functions is deprecated in PHP >= 5.3

Also for email validation better used filter_var

if (!filter_var(trim($_POST['email']), FILTER_VALIDATE_EMAIL))
    echo 'Email is incorrect';
like image 116
Winston Avatar answered Sep 27 '22 22:09

Winston