Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am using following regular expression :-

PHP
$pat  = "/^[a-z0-9!#$%&*+-=?^_`{|}~]+(\.[a-z0-9!#$%&*+-=?^_`{|}~]+)*";
$pat .= "@([-a-z0-9]+\.)+([a-z]{2,3}";
$pat .= "|info|arpa|aero|coop|name|museum)$/ix";


But, it is not accepting '&'.

Anyone can help me please. ?

For eg:-
If I give email as 'abs&c@gmail.com'.
It only takes 'abs'.
Posted
Updated 31-May-11 20:58pm
v2
Comments
Sergey Alexandrovich Kryukov 1-Jun-11 3:15am    
Cannot reproduce the problem, in simple case. Please, a pattern with "&", expected match and where is fails.
--SA
khushboo86 1-Jun-11 3:20am    
Have you tried email address contains "&", and it is working ??

1 solution

I use this regex for validation: ^[\w-\.|!|#|$|%|&|'|*|+|/|=|?|^]+@([\w-]+\.)+[\w-]{2,10}$ (From C#)

See Wiki[^] for more info on valid email address.

PHP code
PHP
$sourcestring="your source string";
preg_match('/^[\w-\.|!|#|$|%|\&|\'|*|+|\/|=|?|^]+@([\w-]+\.)+[\w-]{2,10}$/',$sourcestring,$matches);
echo print_r($matches,true);
 
Share this answer
 
v5
Comments
khushboo86 1-Jun-11 3:22am    
Please, can you give me complete regex ??
Kim Togo 1-Jun-11 3:40am    
See updated answer.
khushboo86 1-Jun-11 4:15am    
It is not working for '&'.
Kim Togo 1-Jun-11 4:24am    
See updated answer about PHP regex
khushboo86 1-Jun-11 4:25am    
still not... :( :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900