Regex Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreRegex Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 26th, 2009, 11:09 AM
dingi21 dingi21 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2009
Posts: 1 dingi21 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 36 m 10 sec
Reputation Power: 0
Email Regular expression

Hi All,

I am using following regular expression to validate email addresses but somehow it is not validating emails for hyphen or dashes (-).

this email is not valid with following regex: email-email @ email .gov (put spaces as forum blocks email addresses.)

var emailpattern=new RegExp("^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[_A-Za-z0-9-]+)");

Any idea what am i missing even when included hyphen.

Any help would be really appreciated.

Reply With Quote
  #2  
Old February 26th, 2009, 11:37 AM
ChiefWigs1982's Avatar
ChiefWigs1982 ChiefWigs1982 is offline
Cunning Linguist
Dev Shed God 11th Plane (10000 - 10499 posts)
 
Join Date: Jul 2003
Location: I used to live at home, now I stay at the house
Posts: 10,180 ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)  Folding Points: 50746 Folding Title: Beginner FolderFolding Points: 50746 Folding Title: Beginner FolderFolding Points: 50746 Folding Title: Beginner Folder
Time spent in forums: 3 Months 3 Weeks 5 Days 19 h 54 m 23 sec
Reputation Power: 2037
You may be implementing this with JS, but it's more of a general RegEx
question, I think.

I've moved it to the RegEx forum where it should get some attention.

If you have trouble implementing the final solution in your JS, just pop
back into the JS forum and someone should be able to help.

--Jon.
__________________
Support requests via PM will be ignored!
Sites: WordPress Metro Theme | Route of Queue
Read These: The General Rules Thread | The General FAQ Thread | NEW USERS - How to post a question


Reply With Quote
  #3  
Old February 26th, 2009, 11:38 AM
ChiefWigs1982's Avatar
ChiefWigs1982 ChiefWigs1982 is offline
Cunning Linguist
Dev Shed God 11th Plane (10000 - 10499 posts)
 
Join Date: Jul 2003
Location: I used to live at home, now I stay at the house
Posts: 10,180 ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)  Folding Points: 50746 Folding Title: Beginner FolderFolding Points: 50746 Folding Title: Beginner FolderFolding Points: 50746 Folding Title: Beginner Folder
Time spent in forums: 3 Months 3 Weeks 5 Days 19 h 54 m 23 sec
Reputation Power: 2037
You might also find that if you search this forum, someone might have
had a similar problem and posted a solution.

Reply With Quote
  #4  
Old February 26th, 2009, 04:04 PM
ManiacDan's Avatar
ManiacDan ManiacDan is offline
Likely to be eaten by a grue.
Dev Shed God 10th Plane (9500 - 9999 posts)
 
Join Date: Oct 2006
Location: Pennsylvania, USA
Posts: 9,801 ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)  Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 2 Months 3 Weeks 16 h 59 m 20 sec
Reputation Power: 6112
Try this expression on for size:
Code:
^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$
Also, that expression you posted DID match email-email@email.gov for me in PHP. No edits aside from the escapes on your backslashes. Are you sure you're doing them right?

-Dan
__________________
HEY! YOU! Read the New User Guide and Forum Rules

"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

Reply With Quote
  #5  
Old February 26th, 2009, 06:08 PM
fishtoprecords's Avatar
fishtoprecords fishtoprecords is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Sep 2007
Location: outside Washington DC
Posts: 2,642 fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)  Folding Points: 2568392 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2568392 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2568392 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2568392 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2568392 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2568392 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2568392 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2568392 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2568392 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2568392 Folding Title: Super Ultimate Folder - Level 6
Time spent in forums: 3 Weeks 4 Days 23 h 21 m 56 sec
Reputation Power: 3682
Just a warning, the real parsing of email addresses, as specified by RFC822, is really ugly. While its probably possible to do it all with a regex, I've never seen one that is perfect.

But a quick search will get one that is good enough for real world use.

Reply With Quote
  #6  
Old February 26th, 2009, 06:35 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 9th Plane (9000 - 9499 posts)
 
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,385 Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 1 Day 21 h 29 m 56 sec
Reputation Power: 4080
There is a regular expression to validate any RFC 822 compliant address, but the actual expression is over 1 page long and is mind-bogglingly complex.
http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne

Reply With Quote
  #7  
Old February 26th, 2009, 06:57 PM
fishtoprecords's Avatar
fishtoprecords fishtoprecords is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Sep 2007
Location: outside Washington DC
Posts: 2,642 fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)fishtoprecords User rank is General 41st Grade (Above 100000 Reputation Level)  Folding Points: 2568392 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2568392 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2568392 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2568392 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2568392 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2568392 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2568392 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2568392 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2568392 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2568392 Folding Title: Super Ultimate Folder - Level 6
Time spent in forums: 3 Weeks 4 Days 23 h 21 m 56 sec
Reputation Power: 3682
Quote:
Originally Posted by Scorpions4ever
There is a regular expression to validate any RFC 822 compliant address, but the actual expression is over 1 page long and is mind-bogglingly complex.

I didn't know it existed. Thanks.

I can believe on the mind-boggling part

Reply With Quote
  #8  
Old March 2nd, 2009, 04:48 PM
Kravvitz's Avatar
Kravvitz Kravvitz is offline
CSS & JS/DOM Adept
Dev Shed God 30th Plane (19500 - 19999 posts)
 
Join Date: Jul 2004
Location: USA
Posts: 19,831 Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level) 
Time spent in forums: 6 Months 1 Day 19 h 19 m 2 sec
Reputation Power: 4192
Being able to use "+" in my addresses for the purpose sorting messages is useful for me. (Some people call it "plus addressing".) Unfortunately many sites don't allow addresses like that.
Code:
^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(\+[-.\w]*[0-9a-zA-Z])?@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$
__________________
Spreading knowledge, one newbie at a time. I'm available for hire at Dynamic Site Solutions.

Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

Remember people spend most of their time on other people's sites (so don't violate web design conventions).

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > Email Regular expression

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap