form validation

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

    form validation

    Hello,

    i need to change and than validate a form value onSubmit so that one field
    called blz accepts whitespace, but submits the value without whitespace and
    checks it for only numbers and length=8, so that:
    "500 100 60" is valid, and becomes "50010060" because after filtering
    whitespace, the entry is 8 digits long.
    "500-100-60" is not valid and produces a alert.
    a second formfield accepts Whitespace and "-" but also only submits numbers
    (there must be exact 10 digits) and checks for them after filtering " " and
    "-".
    So it should accept "1234567-890", "12 34 56 78-90" and submits "1234567890 "
    but dont accept letters an other characters.

    How do i do that?

    Thanks for any help,
    Martin Nadoll


  • Evertjan.

    #2
    Re: form validation

    Martin Nadoll wrote on 30 okt 2003 in comp.lang.javas cript:
    [color=blue]
    > Hello,
    >
    > i need to change and than validate a form value onSubmit so that one
    > field called blz accepts whitespace, but submits the value without
    > whitespace and checks it for only numbers and length=8, so that:
    > "500 100 60" is valid, and becomes "50010060" because after filtering
    > whitespace, the entry is 8 digits long.
    > "500-100-60" is not valid and produces a alert.
    > a second formfield accepts Whitespace and "-" but also only submits
    > numbers (there must be exact 10 digits) and checks for them after
    > filtering " " and "-".
    > So it should accept "1234567-890", "12 34 56 78-90" and submits
    > "1234567890 " but dont accept letters an other characters.[/color]

    <script>

    function validate(t) {
    t = t.replace(/[ -]+/g,"")
    if (/^\d{10}$/.test(t))
    return t
    else
    return false
    }

    // function returns the 10 digit string or false

    // tests:
    alert(validate( "0123---4 - 456789")+"\n012 3---4 - 456789")
    alert(validate( "0123---4 - 56789")+"\n0123---4 - 56789")
    alert(validate( "123")+"\n1 23")


    </script>





    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

    Comment

    Working...