help modifying script to validate text field

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

    help modifying script to validate text field

    I'm using a script provided by e-mailanywhere, it's a little too big
    for me.
    There's 1 text field and 1 password field in a form.
    OnSubmit, I would like both fields to be validated to look for invalid
    digits (~`!#$%^&*()+=?/). This is not working yet, I don't know why.
    In addition, I would like both fields to require from 1 to 12 digits
    for submition to continue.
    The text field also Lowers Case, can you tell me how to do the same on
    password field?
    I would like to ask that if you reply, please write exactly how you
    would modify the script, it's of a lot more help. Thanks in advance
    for all replies, below is the page I have:

    <html>
    <head>
    <title>Chech Your Email</title>
    <script language="JavaS cript">
    function MM_findObj(n, d) { //v4.01
    var p,i,x; if(!d) d=document;
    if((p=n.indexOf ("?"))>0&&paren t.frames.length ) {
    d=parent.frames[n.substring(p+1 )].document; n=n.substring(0 ,p);}
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.fo rms.length;i++)
    x=d.forms[i][n];
    for(i=0;!x&&d.l ayers&&i<d.laye rs.length;i++)
    x=MM_findObj(n, d.layers[i].document);
    if(!x && d.getElementByI d) x=d.getElementB yId(n); return x;
    }

    function MM_swapImage() { //v3.0
    var i,j=0,x,a=MM_sw apImage.argumen ts; document.MM_sr= new Array;
    for(i=0;i<(a.le ngth-2);i+=3)
    if ((x=MM_findObj( a[i]))!=null){docum ent.MM_sr[j++]=x; if(!x.oSrc)
    x.oSrc=x.src; x.src=a[i+2];}
    }

    function MM_swapImgResto re() { //v3.0
    var i,x,a=document. MM_sr;
    for(i=0;a&&i<a. length&&(x=a[i])&&x.oSrc;i++ ) x.src=x.oSrc;
    }

    function trimspace(str)
    {
    temp_str = "";
    for (i=0; i<str.length; i++) {
    c = str.charAt(i);
    if (c != " "){
    temp_str = str.substring(i , str.length);
    break;
    }
    }

    for (i=temp_str.len gth-1; i>=0; i--) {
    c = temp_str.charAt (i);
    if (c != " ") {
    temp_str = temp_str.substr ing(0, i+1);
    break;
    }
    }

    return temp_str;
    }

    function validate_str(st r) {
    var ok = 1;
    if (str.indexOf("~ ") != -1)
    ok = 0;
    if (str.indexOf("` ") != -1)
    ok = 0;
    if (str.indexOf("! ") != -1)
    ok = 0;
    if (str.indexOf("# ") != -1)
    ok = 0;
    if (str.indexOf('$ ') != -1)
    ok = 0;
    if (str.indexOf("% ") != -1)
    ok = 0;
    if (str.indexOf("^ ") != -1)
    ok = 0;
    if (str.indexOf("& ") != -1)
    ok = 0;
    if (str.indexOf("* ") != -1)
    ok = 0;
    if (str.indexOf("( ") != -1)
    ok = 0;
    if (str.indexOf(") ") != -1)
    ok = 0;
    if (str.indexOf("+ ") != -1)
    ok = 0;
    if (str.indexOf("= ") != -1)
    ok = 0;
    if (str.indexOf("? ") != -1)
    ok = 0;
    if (str.indexOf("/") != -1)
    ok = 0;

    if (ok == 0) {
    alert("Invalid input - cannot contain ~ ` ! # $ % ^ & * ( ) + = ?
    /");
    return -1;

    } else
    return 1;
    }

    function update(theform) {
    var email = trimspace(docum ent.forms[theform].emailaddress.v alue);
    if (email == "") {
    alert("Please Enter Your User Name.");
    return;
    }

    if (email.indexOf( "@") == -1) {

    email = email + "@somepage. com"
    }
    else if (email.indexOf( ".") == -1) {
    alert("Please Enter a Valid Email Address.");
    return;
    }

    document.forms[theform].emailaddress.v alue = email;
    document.forms[theform].submit();
    }

    function lemmein(keypres sed){
    var key;

    if (document.all) {
    key=window.even t.keyCode;
    } else {
    key=keypressed. which;
    };
    if (key==13) {
    update("email") ;
    }
    }

    function handleEnter (field, event) {
    var keyCode = event.keyCode ? event.keyCode : event.which ?
    event.which : event.charCode;
    if (keyCode == 13) {
    var i;
    for (i = 0; i < field.form.elem ents.length; i++)
    if (field == field.form.elem ents[i])
    break;
    i = (i + 1) % field.form.elem ents.length;
    field.form.elem ents[i].focus();
    return false;
    }
    else
    return true;
    }

    // -->
    </script>
    </head>
    <body>
    <form name="email" method="POST"
    action="http://www.e-mailanywhere.co m/servlet/emailLogin">
    <input type="hidden" name="logoutURL " value="http://www.somepage.co m">
    <input type="text" name="emailaddr ess" size="20" value=""
    onkeypress="ret urn handleEnter(thi s, event)"
    onChange="javas cript:this.valu e=this.value.to LowerCase();">
    <input type="password" name="password" onkeypress="ret urn
    handleEnter(thi s, event)" size="19" onBlur="">
    <input type="button" onClick='javasc ript:update("em ail");' value="Log
    In">
    <br>Powered by <a title="e-mailanywhere.co m"
    href="http://www.e-mailanywhere.co m">e-mailanywhere</a>.
    </form>
    </body>
    </html>
  • Janwillem Borleffs

    #2
    Re: help modifying script to validate text field


    "Mike" <msebben@photos helf.net> schreef in bericht
    news:5eee303f.0 311301039.7ff02 75@posting.goog le.com...[color=blue]
    >
    > I would like to ask that if you reply, please write exactly how you
    > would modify the script, it's of a lot more help. Thanks in advance
    > for all replies, below is the page I have:
    >[/color]

    I did a first-aid rewrite of the scripts, check:



    Still needs work, but I think that you will be able to pick it up from here.


    JW



    Comment

    • Mike

      #3
      Re: help modifying script to validate text field

      "Janwillem Borleffs" <jw@jwscripts.c om> wrote in message news:<3fca6d8b$ 0$171$1b62eedf@ news.wanadoo.nl >...[color=blue]
      > "Mike" <msebben@photos helf.net> schreef in bericht
      > news:5eee303f.0 311301039.7ff02 75@posting.goog le.com...[color=green]
      > >
      > > I would like to ask that if you reply, please write exactly how you
      > > would modify the script, it's of a lot more help. Thanks in advance
      > > for all replies, below is the page I have:
      > >[/color]
      >
      > I did a first-aid rewrite of the scripts, check:
      >
      > http://www.jwscripts.com/playground/check_email.php
      >
      > Still needs work, but I think that you will be able to pick it up from here.
      >
      >
      > JW[/color]

      Sorry JW, I don't know how to continue, I'm just a beginner. Any more
      help is appreciated.
      Mike

      Comment

      • Janwillem Borleffs

        #4
        Re: help modifying script to validate text field


        "Mike" <msebben@photos helf.net> schreef in bericht
        news:5eee303f.0 311302030.7035b e62@posting.goo gle.com...[color=blue]
        >
        > Sorry JW, I don't know how to continue, I'm just a beginner. Any more
        > help is appreciated.[/color]

        It's more or less useful now, again see:


        Be aware that the email address validation is rudimentary, anything that
        consists of characters a-z, digits and dots, with an at-sign inbetween is
        considered valid.


        JW




        Comment

        • Lasse Reichstein Nielsen

          #5
          Re: help modifying script to validate text field

          "Janwillem Borleffs" <jw@jwscripts.c om> writes:
          [color=blue]
          > Be aware that the email address validation is rudimentary, anything that
          > consists of characters a-z, digits and dots, with an at-sign inbetween is
          > considered valid.[/color]

          Just a comment because it sounds like you think the e-mail validation
          accepts too much. It's probably both too much and too too little.

          While it might be problematic to accept foo@bar, it's the false
          negatives that are really disasterous, e.g., foo+bar@example .com or
          "Mr. Foo Bar"@example.co m (both of which are perfectly good e-mail
          adresses).

          /L
          --
          Lasse Reichstein Nielsen - lrn@hotpop.com
          DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
          'Faith without judgement merely degrades the spirit divine.'

          Comment

          • Janwillem Borleffs

            #6
            Re: help modifying script to validate text field


            "Lasse Reichstein Nielsen" <lrn@hotpop.com > schreef in bericht
            news:k75g45nw.f sf@hotpop.com.. .[color=blue]
            >
            > Just a comment because it sounds like you think the e-mail validation
            > accepts too much. It's probably both too much and too too little.
            >[/color]

            As I said, I consider it rudimentary, which indicates that it's everything
            but perfect.


            JW



            Comment

            Working...