Matching an email with a port number

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
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Matching an email with a port number

Post by evilmonkey »

Hello. I have a regular expression (pretty good one I might add), but it has one downfall: it does not match a port number, in fact, it negates the whole email if there is a port number. Eg, it will match "admin@vagonweb.com", but not "admin@vagonweb.com:25". How can I add that support? Mind, the port is very optional, and I want it to match the string even if I have no port. Here's the regular expression:

Code: Select all

їa-zA-Z]ї\w\.-]*їa-zA-Z0-9]@їa-zA-Z0-9]ї\w\.-]*їa-zA-Z0-9]\.їa-zA-Z]їa-zA-Z\.]*їa-zA-Z]
Thanks!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

untested

Code: Select all

^їa-zA-Z0-9_.-]+@(їa-zA-Z0-9_-]+\.)+їa-zA-Z]{2,4}(:(ї0-5]ї0-9]{4}|6ї0-4]ї0-9]{3}|65ї0-4]ї0-9]{2}|655ї0-2]ї0-9]|6553ї0-5]|ї0-9]{1,4}|ї0-9a-fA-F]{4}))?$
Course, this only covers romanized domain-names...

[edit: made a tweak for the port restriction.]
Last edited by feyd on Thu Jul 22, 2004 11:01 am, edited 2 times in total.
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post by evilmonkey »

romanized?

Your expresseion works, you just missed a closing bracket ")". Here is is, in working order:

Code: Select all

^їa-zA-Z0-9_.-]+@(їa-zA-Z0-9_-]+\.)+їa-zA-Z]{2,4}(:(ї0-9]{1,5})|ї0-9a-fA-F]{4})?$
Thanks :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

:oops: you actually placed the right paren in slightly wrong place, I corrected mine.. still untested though.. :)
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post by evilmonkey »

Whoa, that's complicated...thanks feyd!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yeah.. I thought about it for a bit.. and had to impose the port numbering restrictions.. although it may need to go to 65536, hmm... According to this [auditmypc.com] the range is 0-65535.. ok. :)
Post Reply