Solved

Email validation

Posted on 2008-09-30
2
416 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
Comment Utility
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
Comment Utility
@ 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

743 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

16 Experts available now in Live!

Get 1:1 Help Now