How to fix “Function eregi() is deprecated” in PHP 5.3.0 September 25, 2011

Form validation is required to prevent web form abuse by malicious users . Improper validation of form data is one of the main causes of security vulnerabilities . It exposes your website to attacks such as header injections , cross-site scripting , and SQL injections .

header injection attacks can be used to send email spam from your web server

cross-site scripting may allow an attacker to post any data to your site

SQL injection may corrupt your database backend

A mandatory practice is to always implement client / server-side validation techniques on all input fields of submitted content by the user . This article will focus on validating the email-address field , I used to use eregi for validating email address input that matches to the regular expression . That would return true if given email address is matches to username@domain.com pattern. Unfortunately, after upgrading PHP to the earlier version (5.3.0), it wont work properly . This is because eregi is one of several functions that are deprecated in the new version of PHP . Solution : Use preg_match with the ‘i’ modifier instead. i means that regular expression is case insensitive . So the code become like this :