Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Email validation

Posted on 2008-09-30
2
Medium Priority
?
428 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

722 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