form field validation

M

Martin Nadoll

Hello,

i have a few problems with form field validation:

First i have to check, wether a field is filled with 10 integer numbers.
Also allowed is " " and "-" but no letters, and the input of numbers must
be ten e.g.
"123456-78-9 0" should be allowed and also "12 34 67 67---56" also,
but not "123456789". This should show a alert-message.("Please enter 10
numbers").

Is there any help for me?
Thanks a lot,
Martin Nadoll
 
T

Thomas Kemetmüller

Hi!
I'm not that good in Javascript but maybe this could work:

say str is your string:

var str="0123 4-567 89";

for(i=0, ncount=0;i<str.length;i++)
{
if( str.charAt(i) >= '0' && str.charAt(i) <= '9' )
ncount = ncount + 1;
else
if( str.charAt(i) != ' ' && str.charAt(i) != '-')
alert("no letters allowed, except '-' and blank");
}
if(ncount != 10)
alert("please enter 10 numbers!");

i hope i helped you


----- Original Message -----
From: "Martin Nadoll" <[email protected]>
Newsgroups: comp.lang.javascript
Sent: Thursday, October 30, 2003 5:35 PM
Subject: form field validation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top