By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,940 Members | 1,391 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,940 IT Pros & Developers. It's quick & easy.

form validation

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.