Email validator not allowing '.' in email address before '@'

Discussion in 'Javascript' started by gullyou@googlemail.com, Dec 22, 2005.

  1. Guest

    Sorry I crossposted this to java group. Didn't know distinction
    between Java & Javascript

    Hi,


    I'm not a Java script programmer but have this web page with a form
    form that
    includes a field to input an email address. My problem is that the
    validator won't allow addresses that include a '.' before the @ sign to

    be entered (such as )


    It seems like (3>intIsDOT-intIsAT) || (4>intLengthA-intIsDOT)){


    may be causing the problem. Anyone have an idea that will allow me to
    screen out invalid addresses but still allow a . before the @? I would

    like to continue using the same script, only modified to allow the '.'
    if possible.


    Here's the portion of the script that seems to be involved:


    function fnEmailValidation(oTag){
    var intLengthA= oTag.value.length;
    var intIsAT = oTag.value.indexOf("@");
    var intIsDOT = oTag.value.indexOf(".");
    if (intLengthA<6 || intIsAT<1 ||
    (3>intIsDOT-intIsAT) ||
    (4>intLengthA-intIsDOT)){
    return false;
    }
    var
    strTextAfterDot=oTag.value.substring(intIsDOT+1,intLengthA);
    intLengthA= strTextAfterDot.length;
    for (var x=0;x<intLengthA;x++){
    if
    (isNaN(strTextAfterDot.substring(x,x+1))==true) return true;
    }
    return false;
    }
     
    , Dec 22, 2005
    #1
    1. Advertising

  2. wrote:

    > [...]
    > I'm not a Java script programmer


    I am not either, since there is no "Java script".

    > but have this web page with a form form that includes a field to input an
    > email address. My problem is that the validator won't allow addresses
    > that include a '.' before the @ sign to
    >
    > be entered (such as )


    Your example address does not conform to RFC2822, the algorithm would
    rightfully refuse it.

    > It seems like (3>intIsDOT-intIsAT) || (4>intLengthA-intIsDOT)){
    >
    >
    > may be causing the problem. Anyone have an idea that will allow me to
    > screen out invalid addresses but still allow a . before the @? [...]


    <http://groups.google.com/groups?q=valid+%22mail+address%22+group%3Acomp.lang.javascript&start=0&scoring=d&>

    > [overly complicated inefficient code that I refuse to review]


    Ever heard of Regular Expressions? Supported since IE3 (August 1996),
    NN4 (June 1997).


    PointedEars
     
    Thomas 'PointedEars' Lahn, Dec 22, 2005
    #2
    1. Advertising

  3. Guest

    Thanks, PointedEars. No, I haven't heard of regular expressions. This
    isn't my script and it does seem more complicated than other email
    validator scripts I've seen on the web. I'm not a web programmer, I
    just generally modify existing stuff to come up with what I want if I
    need to do something I don't know how to do.

    Not being a programmer, I wouldn't necessarily be able to distinguish
    the necessary from the unnecessarily complicated. My attempts at
    modifying the script have all resulted in the form accepting ANYTHING
    in the email address field, unfortunately.

    Thanks for the links. I'll do some more looking, and maybe your
    reference to "regular expressions" will lead me to something useful.

    No big deal. Someone's going to take care of this problem, even if it
    isn't me. It's not exactly my webpage, after all.

    Thanks again.
     
    , Dec 22, 2005
    #3
  4. McKirahan Guest

    <> wrote in message
    news:...
    > Sorry I crossposted this to java group. Didn't know distinction
    > between Java & Javascript
    >
    > Hi,
    >
    >
    > I'm not a Java script programmer but have this web page with a form
    > form that
    > includes a field to input an email address. My problem is that the
    > validator won't allow addresses that include a '.' before the @ sign to
    >
    > be entered (such as )
    >
    >
    > It seems like (3>intIsDOT-intIsAT) || (4>intLengthA-intIsDOT)){
    >
    >
    > may be causing the problem. Anyone have an idea that will allow me to
    > screen out invalid addresses but still allow a . before the @? I would
    >
    > like to continue using the same script, only modified to allow the '.'
    > if possible.
    >
    >
    > Here's the portion of the script that seems to be involved:
    >
    >
    > function fnEmailValidation(oTag){
    > var intLengthA= oTag.value.length;
    > var intIsAT = oTag.value.indexOf("@");
    > var intIsDOT = oTag.value.indexOf(".");
    > if (intLengthA<6 || intIsAT<1 ||
    > (3>intIsDOT-intIsAT) ||
    > (4>intLengthA-intIsDOT)){
    > return false;
    > }
    > var
    > strTextAfterDot=oTag.value.substring(intIsDOT+1,intLengthA);
    > intLengthA= strTextAfterDot.length;
    > for (var x=0;x<intLengthA;x++){
    > if
    > (isNaN(strTextAfterDot.substring(x,x+1))==true) return true;
    > }
    > return false;
    > }
    >


    Will this help?

    <html>
    <head>
    <title>EmailValidation.htm</title>
    <script type="text/javascript">
    function fnFormValidation(that) {
    var oTag = that.Email;
    if (!fnEmailValidation(oTag)) return false;
    return true;
    }
    function fnEmailValidation(oTag) {
    var regx = /^[\w-\.]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,3}$/;
    if (oTag.value.length == 0) {
    alert("Email is missing!");
    } else if (!regx.test(oTag.value)) {
    alert("Email is invalid!");
    }
    }
    </script>
    </head>
    <body>
    <form name="form1" onsubmit="return fnFormValidation(this)">
    <input type="text" name="Email" size="50" maxlength="50">
    <input type="submit" value="Submit">
    </form>
    </body>
    </html>
     
    McKirahan, Dec 22, 2005
    #4
  5. Guest

    It just might. Thanks. I'll check it out and see.
     
    , Dec 22, 2005
    #5
  6. JRS: In article <>, dated
    Thu, 22 Dec 2005 14:04:15 local, seen in news:comp.lang.javascript,
    McKirahan <> posted :

    >Will this help?


    >function fnFormValidation(that) {
    > var oTag = that.Email;
    > if (!fnEmailValidation(oTag)) return false;
    > return true;
    >}
    >function fnEmailValidation(oTag) {
    > var regx = /^[\w-\.]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,3}$/;
    > if (oTag.value.length == 0) {
    > alert("Email is missing!");
    > } else if (!regx.test(oTag.value)) {
    > alert("Email is invalid!");
    > }
    >}


    Reposting stale code that you've found somewhere, or writing code that
    looks like that, is no help to anyone.

    That code only allows TLDs of two or three characters.

    It also does not allow on the left at least one character, $, which I
    know to be valid.

    Normally, one would expect a validation function to return a value.

    OP : see <URL:http://www.merlyn.demon.co.uk/js-valid.htm>.

    --
    © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
    <URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
     
    Dr John Stockton, Dec 23, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. D James
    Replies:
    6
    Views:
    1,587
    jiuqin
    Jun 13, 2007
  2. UJ
    Replies:
    2
    Views:
    346
  3. Replies:
    4
    Views:
    947
    Richter~9.6
    Feb 13, 2007
  4. Keith G Hicks
    Replies:
    1
    Views:
    382
    Keith G Hicks
    Apr 28, 2008
  5. Zeynel
    Replies:
    1
    Views:
    583
    alex23
    Dec 6, 2010
Loading...

Share This Page