url or email

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
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

url or email

Post by shiznatix »

I need to find out of a string is either a URL or a E-mail address. I image a regular expression would do it but the only real way I could think would to check for a @ sign and if its found then its a email if not its a URL but I think that should a little sketchy. Any other ideas?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

this will match an email address

Code: Select all

^(ї0-9a-zA-Z]+ї-._+&])*ї0-9a-zA-Z]+@(ї-0-9a-zA-Z]+ї.])+їa-zA-Z]{2,6}$
this will match a url

Code: Select all

^(http|https|ftp)\://їa-zA-Z0-9\-\.]+\.їa-zA-Z]{2,3}(:їa-zA-Z0-9]*)?/?(їa-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*ї^\.\,\)\(\s]$
i think :lol:
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

thanks much
Post Reply