Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Email validation

Posted on 2008-09-30
2
Medium Priority
?
431 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
Suggested Courses

879 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