Click to See Complete Forum and Search --> : Javascript Form Validation - HELP


Terra
01-09-2003, 12:26 PM
Can anybody spot anything wrong with this???

It goes through about half of the boxes then stops GRRR

I found a few typos (some with a little help thx guys)

:o Am sooooo not happy with not getting it working yet!

PLEASE HELP

Also does anybody know how i would get it to validate a box so it checked for 2 letters, then 5 numbers?? for example: GL12345??

swon
01-09-2003, 12:47 PM
Hi, hope that works for you:

Terra
01-09-2003, 12:52 PM
OMG i love you!!!!

Do you wanna get married?

Thank you soooo much! That really helps!

swon
01-09-2003, 12:58 PM
:D

Terra
01-11-2003, 09:16 AM
Am using the following to validate a box within a form (see attached above). Am getting really hacked off with my javascript book now.

I need to make sure the box validates the data as: 2 Numbers followed by 5 Letters, GRRR

Can any of you point me in the right direction?
Am thinking I have to alter this bit, just not sure how:
for (var i = 0; i < stuNumber.length; i++) // stuNumber ?

---------------------------------------------------

function validateStudentNumber(stuNumber)
{
if (isBlank(stuNumber)) // student number field blank?
{
alert("Please enter your student number")
return false
}
for (var i = 0; i < stuNumber.length; i++) // stuNumber ?
{
var testChar = stuNumber.charAt(i)
if (testChar < "0" || testChar > "9")
if (testChar < "a" || testChar > "z")
{
alert("Enter your student number in the correct format")
return false
}
return true
}
}

Webskater
01-11-2003, 09:37 AM
var pushon = false
for (var i = 0; i < stuNumber.length; i++) // stuNumber ?
{
var testChar = stuNumber.charAt(i)
if (i < 2)
{
if (isNaN(testChar)) { var pushon=true; }

else if (i >= 2)
{

}
{
alert("Enter your student number in the correct format")
return false
}
return true
}

Webskater
01-11-2003, 09:42 AM
Please ignore my last post. I pressed the space bar twice and it submitted!
What I was trying to say was:
In your loop test the first two characters (i < 2) and if isNaN is true then carry on. Then test the rest of the characters (i >=2) and if isNaN is false then carry on. You can also test the length of the loop to make sure they have entered the correct number of characters.

Terra
01-11-2003, 09:44 AM
Cheers, I wish books could be that direct, is naff they make it seem like foreign languages!

:)