Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #18231

Re: Email Vali8dation Problem

From Andreas Bergmaier <andber93@web.de>
Newsgroups comp.lang.javascript
Subject Re: Email Vali8dation Problem
Date 2013-01-24 01:58 +0100
Organization albasani.net
Message-ID <kdq101$r76$1@news.albasani.net> (permalink)
References <amb6f9Fhvk3U1@mid.individual.net>

Show all headers | View raw


Mel Smith schrieb:
> Hi:
>
>      I have the following undernoted isEMail() function defined in the <head>
> section of a  page
>
>      This function returns false for:
>
>                  m.smith@example.com
>                  m.smith@dumbo.example.com
>
>      Woud someone take a 'stab' at correcting the regex expression below to
> allow the above formatted email addresses to return 'true'.
 >
 > 
/^([a-zA-Z0-9_\-])+\@(([a-zA-Z0-9\-])+)+(\.[a-zA-Z]{2,6})(\.[a-zA-Z]{2})?$/i.test(email) 


The part before the at-sign does not allow dots.

The part after the at-sign does only allow two-level-domains with a 
2-to-6-char TLD or three-level domains with two-char TLD and 2-to-6-char 
second-level-domain. "example" has 7 chars.

Also, the expression (([a-zA-Z0-9\-])+)+ is very odd and could lead to 
catastrophic backtracking.

> google brings up dozens of variations for this task, but I'd like
> to get the 'perfect' one :((

There is no perfect one. Email adresses in RFC format are even not 
parsable by regular expressions.

However, don't overcomplificate the task. Checking whether the entered 
address is syntactically valid *and* catching all edge cases is hardly 
possible. At last, you never know whether the user entered an existing 
mail or just "john.doe@example.com".

Using /^\s*(.+@.+)\s*$/ should be enough to check whether the entered 
string looks like an email adress, and warning the user if it does not.

regards,
  Bergi

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Email Vali8dation Problem "Mel Smith" <med_cutout_syntel@aol.com> - 2013-01-23 15:27 -0700
  Re: Email Vali8dation Problem Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2013-01-24 01:18 +0100
    Re: Email Vali8dation Problem Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-24 02:06 +0100
      Re: Email Vali8dation Problem Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2013-01-24 22:30 +0100
        Re: Email Vali8dation Problem Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-24 22:38 +0100
    Re: Email Vali8dation Problem Jeff North <jnorthau@yahoo.com.au> - 2013-01-24 13:04 +1100
      Re: Email Vali8dation Problem Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2013-01-24 22:24 +0100
        Re: Email Vali8dation Problem Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-24 22:40 +0100
        Re: Email Vali8dation Problem Jeff North <jnorthau@yahoo.com.au> - 2013-01-26 00:12 +1100
          Re: Email Vali8dation Problem Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2013-01-25 21:56 +0100
            Re: Email Vali8dation Problem Jeff North <jnorthau@yahoo.com.au> - 2013-01-26 10:56 +1100
              Re: Email Vali8dation Problem Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2013-01-26 01:56 +0100
                Re: Email Vali8dation Problem Jeff North <jnorthau@yahoo.com.au> - 2013-01-26 20:14 +1100
                Re: Email Vali8dation Problem Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2013-01-26 13:21 +0100
                Re: Email Vali8dation Problem Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2013-01-26 15:07 +0200
                Re: Email Vali8dation Problem "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2013-01-26 16:04 +0200
                Re: Email Vali8dation Problem Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2013-01-26 16:37 +0200
                Re: Email Vali8dation Problem Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2013-01-26 15:46 +0100
                Re: Email Vali8dation Problem Jeff North <jnorthau@yahoo.com.au> - 2013-01-27 10:30 +1100
  Re: Email Vali8dation Problem Andreas Bergmaier <andber93@web.de> - 2013-01-24 01:58 +0100
    Re: Email Vali8dation Problem Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-24 02:08 +0100
    Re: Email Vali8dation Problem "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-01-24 10:25 +0100
  Re: Email Vali8dation Problem Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2013-01-24 11:15 +0100
    Re: Email Validation Problem "Mel Smith" <med_cutout_syntel@aol.com> - 2013-01-24 08:53 -0700
      Re: Email Validation Problem Luc Yen <luc@goal.tw> - 2013-01-25 13:53 -0800
  Re: Email Vali8dation Problem Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-01-24 19:59 +0000
    Re: Email Vali8dation Problem "Mel Smith" <med_cutout_syntel@aol.com> - 2013-01-25 09:37 -0700
      Re: Email Vali8dation Problem Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2013-01-25 22:08 +0100
        Re: Email Vali8dation Problem Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-01-26 20:51 +0000

csiph-web