Form Validation Help

Hi,

I need to come up with a script for a not-so-simple form field validation and would love some advice as to how to start.

Here's the lowdown:

The field can accept up to a 15-digit number;
I need to validate the first 4 digits of this number against a list of 4-digit numbers;

Any thoughts.

Thanks,
Paul

Comments

  • [b][red]This message was edited by NCS_One at 2007-2-3 14:29:30[/red][/b][hr]
    Hi

    I only use IE and Opera, i tested it and works fine.
    I had to do a handle to "onpaste" because IE uses it not Opera,
    and if users paste something like "123a" in IE that would be accepted
    because the HandleKeyPress only handles KeyPress.

    Here it goes :
    [code]


    Test1


    var My4Numbers = 1234;

    function HandleKeyPress(e)
    {
    var keynum;
    var keychar;
    var numcheck;

    if(window.event)
    {
    keynum = e.keyCode;
    }
    else if(e.which)
    {
    keynum = e.which;
    }

    keychar = String.fromCharCode(keynum);
    numcheck = /d/;
    return numcheck.test(keychar);
    }

    function HandlePaste()
    {
    var CBText = window.clipboardData.getData("Text");
    var keychar = CBText;
    var numcheck;

    numcheck = /d/;
    return numcheck.test(keychar);
    }

    function HandleClick()
    {
    var AuxStr = Text1.value;
    var AuxStr2;

    AuxStr2 = AuxStr.slice(0, 4);
    if (My4Numbers == AuxStr2)
    {
    Div1.innerText = "Validated";
    }
    else
    {
    Div1.innerText = "Not Validated";
    }
    }








    [/code]
    Hope it helps.


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion