Solved

Email validation

Posted on 2008-09-30
2
417 Views
Last Modified: 2011-09-20
Hi experts!

I have a question related to e-mail validation. The validation code is bellow. This has a problem that it does not validate an email address which looks like: a-d@bla.com [with minus sign] Can anyone suggest a solution?
element.match(/(^[a-z0-9]([a-z0-9_\.]*)@([a-z0-9_\.]*)([.][a-z]{2,3})$)|(^[a-z0-9]([a-z0-9_\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3})(\.[a-z]{2,3})*$)/i)

Open in new window

0
Comment
Question by:dlcnet
2 Comments
 
LVL 3

Accepted Solution

by:
DigitalSnorkle earned 500 total points
ID: 22603828
Adding \- to expression should suffice?

Something like the snippit 1 below if I remeber my regex.

Snippit 2 will alow allow you to have blah@foo-bar.com names

It's up to you how far you take it, you've got ot trade off usefulness with performance top.

There an absolute version here: http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html
It fills the whole RFC822 standard, but it's hideously slow :)
1.

/(^[a-z0-9]([a-z0-9_\.\-]*)@([a-z0-9_\.]*)([.][a-z]{2,3})$)|(^[a-z0-9]([a-z0-9_\.\-]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3})(\.[a-z]{2,3})*$)/i
 

2.

/(^[a-z0-9]([a-z0-9_\.\-]*)@([a-z0-9_\.\-]*)([.][a-z]{2,3})$)|(^[a-z0-9]([a-z0-9_\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3})(\.[a-z]{2,3})*$)/i

Open in new window

0
 

Author Comment

by:dlcnet
ID: 22603950
@ DigitalSnorkle

Thank you for your quick reply. Unfortunatelly it does not work :( I am implementing this in .jspx site and I am using prototype 1.6-02 The entire line looks like:
 return !!$F(element.match(EXPRESION));
 
 I am totally lost now :(

return !!$F(element.match(/(^[a-z0-9]([a-z0-9_\.\-]*)@([a-z0-9_\.\-]*)([.][a-z]{2,3})$)|(^[a-z0-9]([a-z0-9_\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3})(\.[a-z]{2,3})*$)/i));

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
egit plugin on eclipse 8 40
Initialize SharePoint Online List Values in Quick Edit 7 23
tomcat not starting 6 31
two layers of simple javascript validation 2 26
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now