Specific E-Mail Validation Script

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ibizara

    Specific E-Mail Validation Script

    Please could anyone help I need a validation script on and input field
    email to include/exclude the below?
    If it is even possible even??
    Many Thanks in advanced, Regards, Jason

    -----------------------------------------------------------------------------

    (Note " * " is NOT a wildcard in the instances below)

    include:
    a-Z 0-1 * _ - @ a-Z 0-1 _ - . a-Z 0-1

    exclude:
    *@hsbc.com
    *@barclays.com
    *@hotmail.com

    -----------------------------------------------------------------------------

    if (theForm.email. value == "")
    {
    alert("Please enter a valid email");
    theForm.email.f ocus();
    return (false);
    }

    var checkemail = "@.";
    var checkStr = theForm.email.v alue;
    var emailValid = false;
    var emailAt = false;
    var emailPeriod = false;
    for (i = 0; i < checkStr.length ; i++)
    {
    ch = checkStr.charAt (i);
    for (j = 0; j < checkemail.leng th; j++)
    {
    if (ch == checkemail.char At(j) && ch == "@")
    emailAt = true;
    if (ch == checkemail.char At(j) && ch == ".")
    emailPeriod = true;
    if (emailAt && emailPeriod)
    break;
    if (j == checkemail.leng th)
    break;
    }

    if (emailAt && emailPeriod)
    {
    emailValid = true
    break;
    }
    }
    if (!emailValid)
    {
    alert("Please enter a valid email");
    theForm.email.f ocus();
    return (false);
    }

    -----------------------------------------------------------------------------

    <form name="whitelist " method="post" action="submit. php">
    <input name="email" type="text" id="email"
    onblur="lowerCa se(this.id)">
    <i>user@company .com (*@company.com = anything)</i><br>
    <i>Please do <font color="red">NOT </fontadd <u>*@hotmail.co m</u,
    only to company domains eg. <u>*@scruttonbl and.co.uk</u></i><br>
    <i>Also please <font color="red">exc lude</fontBank email addresses
    (@rbs.co.uk @barclays.co.uk @lloydstsb.com @hsbc.co.uk @natwest.com)</
    i><br>
    <input name="submit" type="submit" id="submit" value="Submit">
  • ibizara

    #2
    Re: Specific E-Mail Validation Script

    Please could anyone help I need a validation script on and input field
    email to include/exclude the below?
    >
    You are wasting your time doing it that way.  Invest a little time in
    learning the beginnings of RegExps, and you will soon profit.
    As it does seem pretty difficult to get it just right i'm going to try
    searching a few places and my result I will post here.

    Might try...

    Check whole email and accept if they have ¬

    a-Z 0-1 * _ - @ .

    Check whole email, Must have the below ¬

    @ .

    Thanks for your reply.

    J

    Comment

    • ibizara

      #3
      Re: Specific E-Mail Validation Script

      On 24 Jan, 10:24, ibizara <ibiz...@google mail.comwrote:
      >Please could anyone help I need a validation script on an input field
      >email to include/exclude the below?
      >
      You are wasting your time doing it that way.  Invest a little time in
      learning the beginnings of RegExps, and you will soon profit.
      >
      As it does seem pretty difficult to get it just right i'm going to try
      searching a few places and my result I will post here.
      >
      Might try...
      >
      Check whole email and accept if they have ¬
      >
      a-Z 0-1 * _ - @ .
      >
      Check whole email, Must have the below ¬
      >
      @ .
      Achieved what I needed but in PHP rather than JavaScipt

      <?php
      // Receiving variables
      @$email = addslashes($_PO ST['email']);

      if (! ereg('^[*a-z\'0-9]+([._-][*a-z\'0-9]+)*@([a-z0-9]+([._-][a-
      z0-9]+))+$', $email)){
      include_once("e rror.inc");
      die();
      }

      if(preg_match('/\*@(hotmail|rbs |barclays|lloyd stsb|hsbc|natwe st)\.(com|
      co\.uk)$/i',$email)){
      include_once("n ot_allowed.inc" );
      die();
      }
      ?>

      But if anyone wants to help convert the above to JS... ?

      J




      Comment

      • Dr J R Stockton

        #4
        Re: Specific E-Mail Validation Script

        In comp.lang.javas cript message <a10b516c-4a7e-42ec-a344-ce264efaa668@u1
        0g2000prn.googl egroups.com>, Wed, 23 Jan 2008 09:13:17, ibizara
        <ibizara@google mail.composted:
        >Please could anyone help I need a validation script on and input field
        >email to include/exclude the below?
        You are wasting your time doing it that way. Invest the time in
        learning RegExps first.

        It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

        --
        (c) John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v6.05 IE 6
        news:comp.lang. javascript FAQ <URL:http://www.jibbering.c om/faq/index.html>.
        <URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
        <URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.

        Comment

        Working...