# Valid Email function

**URL:** <https://forum.kirupa.com/t/valid-email-function/68159>\
**Category:** programming\
**Created:** [October 22, 2004, 3:30pm UTC](https://forum.kirupa.com/t/valid-email-function/68159 "2004-10-22T15:30:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lbeetles](https://avatars.discourse-cdn.com/v4/letter/l/2bfe46/32.png) [@lbeetles](https://forum.kirupa.com/u/lbeetles)\
**Post date:** [October 22, 2004, 3:30pm UTC](https://forum.kirupa.com/t/valid-email-function/68159/1 "2004-10-22T15:30:52Z")

</div>

I have a php function to validate an email address in my flash form, but there is one problem.

The function **valid\_email** only works if your email address is something like:

**[test@test.com](mailto:test@test.com)**

But it comes up invalid email if your address is:

\*\*test@test.co.uk \*\*  
**[color=#006699]test@test-test.com[/color]**

Does anyone know how to change the function so you can have email address like:

\*\*test@test.co.uk \*\*  
**[[u][color=#006699]test@test-test.co.uk[/color][/u]](mailto:test@test-test.co.uk)**

as well as [[u][color=#006699]test@test.com[/color][/u]](mailto:test@test.com).

Here is the function from the tutorial:

```php
 function valid_email($email) 
{ 
// check if email is valid 
if( !eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" 
."@([a-z0-9]+([\.-][a-z0-9]+))*$",$email, $regs)) 
{ 
	 return false; 
} else if( gethostbyname($regs[2]) == $regs[2] ) 
{ 
	 // if host is invalid 
	 return false; 
} else { 
	 return true; 
} 
} 

```
