469,327 Members | 1,200 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,327 developers. It's quick & easy.

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
Jul 20 '05 #1
1 3095
Martin Nadoll wrote on 30 okt 2003 in comp.lang.javascript:
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.


<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")+"\n0123---4 - 456789")
alert(validate("0123---4 - 56789")+"\n0123---4 - 56789")
alert(validate("123")+"\n123")
</script>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

17 posts views Thread by Phil Powell | last post: by
4 posts views Thread by TG | last post: by
16 posts views Thread by Hosh | last post: by
9 posts views Thread by julie.siebel | last post: by
27 posts views Thread by Chris | last post: by
11 posts views Thread by Rik | last post: by
5 posts views Thread by lucyh3h | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by listenups61195 | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.