Simple RegEx question [SOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dyonak
Forum Commoner
Posts: 56
Joined: Wed Jun 22, 2005 10:22 am
Location: Minneapolis, MN
Contact:

Simple RegEx question [SOLVED]

Post by dyonak »

I'm sure this will be pretty easy for someone out there but I can't quite get it. I've got two different ways of accessing the same script to send mail but they format the e-mail slightly different both times. One form formats the email addy properly name@domain.com but the other formats it as name@domain.com@. I want to check the variable in the mail script to see if it has the excess @ at the end and trim it if so. My current regex is written. . .

Code: Select all

if (preg_match ('/[@]{2}/',$email)){
echo 'Multiple @'s';
}
Any ideas?
Last edited by dyonak on Wed Nov 02, 2005 10:23 am, edited 1 time in total.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Code: Select all

preg_match('/@$/',$email);
maybe
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
dyonak
Forum Commoner
Posts: 56
Joined: Wed Jun 22, 2005 10:22 am
Location: Minneapolis, MN
Contact:

Post by dyonak »

That's it, thanks man!
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Probably not worth firing up the regex engine for that :)

Code: Select all

//    - - -       if last char is "@"        then ret. -1 char      else don't change
$trimmed = substr($string, -1) == '@' ? substr($string, 0, -1) : $string;
Post Reply