[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

simple regex question

With the 1000's of new TLDs coming shortly I'm not going to bother validating email addresses using old regular expressions, however I'm trying  to add a basic regex  to ensure a string has:

(at least one character)@(at least one character).(at least one character)

anyone know what that regular expression would look like?
0
tf2012
Asked:
tf2012
1 Solution
 
Dan CraciunIT ConsultantCommented:
\w+@\w+\.\w+

HTH,
Dan
0
 
MazdajaiCommented:
That would work but it will ignore something like 'abc-a.b_c@ab-c.com'.

A valid email address can have dash, dot and underscore.

[a-zA-Z0-9_.-]+@[a-zA-Z0-9.-]+

Open in new window

0
 
ozoCommented:
(at least one character)@(at least one character).(at least one character)
.+\@.+\..+
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Terry WoodsIT GuruCommented:
For validation purposes, you may want to at least disallow space and subsequent @ characters, and also disallow other characters before and after the email address, if the email address is meant to be by itself such as in a form. Adjusting @ozo's pattern:
^[^\s@]+@[^\s@]+\.[^\s@]+$

Open in new window

There may be other characters that you want to exclude. This page discusses the allowed characters, and may be of interest if you want to complicate things further :-)
0
 
ozoCommented:
space and @ characters are actually allowed when properly quoted, as discussed in TerryAtOpus's link, but a regular expression to properly handle the official RFC822 spec can get pretty complicated, and may not be worth using given that there are other ways of checking email addresses, and that there can be other issues with email addresses besides whether they have a valid format.
0
 
tf2012Author Commented:
great thanks
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now