page validation script - question

Discussion in 'ASP General' started by Raphael Gluck, Jul 26, 2004.

  1. HI

    I am wondering if anyone can help me

    I added a little script to a form page, so that a couple of fields have to
    filled in. One contains an obligatory field for number data, one for regular
    text.
    However it seems that when a user will just enter a few spaces in the
    required, they seem to be able to pass the validation script.

    Here is the script, How should i modify it to exclude spaces?

    Many thanks

    Raphael

    <script language="JavaScript" type="text/JavaScript">
    <!--
    function MM_validateForm() { //v4.0
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2];
    val=MM_findObj(args);
    if (val) { nm=val.name; if ((val=val.value)!="") {
    if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
    if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an
    e-mail address.\n';
    } else if (test!='R') { num = parseFloat(val);
    if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
    if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
    min=test.substring(8,p); max=test.substring(p+1);
    if (num<min || max<num) errors+='- '+nm+' must contain a number
    between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is
    required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
    }
    //-->
    </script>
    Raphael Gluck, Jul 26, 2004
    #1
    1. Advertising

  2. Raphael Gluck

    John Guest

    First of all: this is a ASP group.

    Trim your field and if "" exit the function
    Or if intr(field," ") 'two spaces' exit
    Search the net for email validator scripts @ is not the only thing needed
    for a valid script
    John, Jul 26, 2004
    #2
    1. Advertising

  3. Raphael Gluck

    Jeff Cochran Guest

    On Mon, 26 Jul 2004 11:40:45 +0100, "Raphael Gluck" <>
    wrote:

    >I am wondering if anyone can help me


    Nope. This is an ASP forum, you're asking for help on a client-side
    JavaScript script. Try a JavaScript forum.

    Jeff

    >I added a little script to a form page, so that a couple of fields have to
    >filled in. One contains an obligatory field for number data, one for regular
    >text.
    >However it seems that when a user will just enter a few spaces in the
    >required, they seem to be able to pass the validation script.
    >
    >Here is the script, How should i modify it to exclude spaces?
    >
    >Many thanks
    >
    >Raphael
    >
    ><script language="JavaScript" type="text/JavaScript">
    ><!--
    >function MM_validateForm() { //v4.0
    > var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    > for (i=0; i<(args.length-2); i+=3) { test=args[i+2];
    >val=MM_findObj(args);
    > if (val) { nm=val.name; if ((val=val.value)!="") {
    > if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
    > if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an
    >e-mail address.\n';
    > } else if (test!='R') { num = parseFloat(val);
    > if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
    > if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
    > min=test.substring(8,p); max=test.substring(p+1);
    > if (num<min || max<num) errors+='- '+nm+' must contain a number
    >between '+min+' and '+max+'.\n';
    > } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is
    >required.\n'; }
    > } if (errors) alert('The following error(s) occurred:\n'+errors);
    > document.MM_returnValue = (errors == '');
    >}
    >//-->
    ></script>
    >
    Jeff Cochran, Jul 26, 2004
    #3
    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. =?Utf-8?B?ZGh1cndpdHo=?=
    Replies:
    1
    Views:
    443
    Teemu Keiski
    Apr 10, 2004
  2. ibiza
    Replies:
    2
    Views:
    5,065
    ibiza
    Feb 8, 2006
  3. EO
    Replies:
    0
    Views:
    126
  4. Sudip
    Replies:
    0
    Views:
    187
    Sudip
    Jul 1, 2005
  5. Robert Cohen
    Replies:
    3
    Views:
    250
    Andrew Durstewitz
    Jul 15, 2003
Loading...

Share This Page