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


Groups > comp.lang.javascript > #19249

Re: Restrict a domain on Email Validation

From Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid>
Newsgroups comp.lang.javascript
Subject Re: Restrict a domain on Email Validation
Date 2013-04-12 19:36 +0100
Organization Home
Message-ID <HGPH6NInQFaRFw+I@invalid.uk.co.demon.merlyn.invalid> (permalink)
References <9e42c475-f0f4-4822-98d4-0291745f3447@googlegroups.com>

Show all headers | View raw


In comp.lang.javascript message <9e42c475-f0f4-4822-98d4-0291745f3447@go
oglegroups.com>, Thu, 11 Apr 2013 10:33:04, GarryJones
<morack@algonet.se> posted:

>I am currently using this code to validate emailadresses on user forms.
>
>function checkform ( form ){
>  if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.bokep
>t.value))){

That RegExp will reject, according to test, at least one perfectly valid
E-mail address; and therefore a large number of valid addresses.  You
should find out the requirements for a valid address before attempting
validation.

There is little point in attempting strict format validation, since the
more important problem is exemplified by an input of 'microsoft.com' by
someone wanting 'microsort.com'.

The only sensible test is that the pattern is not OBVIOUSLY AND
CERTAINLY invalid; so test with /.+@.+\..+/ (untested; see cited site)
[and consider that E-mail address right parts can be in purely numeric
form {IPv4 & IPv6 or other terminology}].


>This has served me well since 2005.

Except that a probably-unknown number of addresses have been incorrectly
deemed invalid.

Your code additionally rejects addresses with trailing whitespace; it
would generally be better to trim leading and trailing whitespace before
doing anything else.


>How can I change the script to block all email addresses from @forbidden.*

Then use another RegExp test to reject any string matching
/@forbidden.*/ (though it might be wise to allow ones from postmaster @
anywhere).

See in <http://www.merlyn.demon.co.uk/js-valid.htm>.


-- 
 (c) John Stockton, nr London UK               Reply address via Home Page.
   news:comp.lang.javascript FAQ <http://www.jibbering.com/faq/index.html>.
   <http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
   <http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

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


Thread

Restrict a domain on Email Validation GarryJones <morack@algonet.se> - 2013-04-11 10:33 -0700
  Re: Restrict a domain on Email Validation Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-11 20:40 +0200
    Re: Restrict a domain on Email Validation Stefan Weiss <krewecherl@gmail.com> - 2013-04-11 20:53 +0200
      Re: Restrict a domain on Email Validation Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-11 21:09 +0200
        Re: Restrict a domain on Email Validation Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-11 21:35 +0200
        Re: Restrict a domain on Email Validation Stefan Weiss <krewecherl@gmail.com> - 2013-04-11 21:49 +0200
          Re: Restrict a domain on Email Validation Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-11 22:04 +0200
            Re: Restrict a domain on Email Validation Stefan Weiss <krewecherl@gmail.com> - 2013-04-11 23:25 +0200
              Re: Restrict a domain on Email Validation Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-11 23:31 +0200
                Re: Restrict a domain on Email Validation Stefan Weiss <krewecherl@gmail.com> - 2013-04-12 00:23 +0200
                Re: Restrict a domain on Email Validation Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-12 00:42 +0200
                Re: Restrict a domain on Email Validation Stefan Weiss <krewecherl@gmail.com> - 2013-04-13 11:36 +0200
                Re: Restrict a domain on Email Validation Scott Sauyet <scott.sauyet@gmail.com> - 2013-04-20 13:30 -0700
    Re: Restrict a domain on Email Validation Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-12 00:51 +0200
  Re: Restrict a domain on Email Validation Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-04-12 19:36 +0100
    Re: Restrict a domain on Email Validation "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-04-13 10:40 +0200

csiph-web