Solved

Email validation

Posted on 2008-09-30
2
418 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jQuery delay animation 3 28
javascript comparing two dates 3 18
how can i check if the text is an Isogram ? 2 25
Java Restore security prompts not working 10 7
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

808 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