Question 1 / Vraag 1 – Basic JavaScript Validaton / Basiese JavaScript validasie

// <![CDATA[
function validate()
{
var firstname = document.getElementById("firstname");
var surname = document.getElementById("surname");
var age = document.getElementById("age");
var email = document.getElementById("email");

if(notEmpty(firstname, "ENTER USERNAME"))
{
if(notEmpty(surname, "ENTER SURNAME"))
{
if(notEmpty(age, "ENTER AGE"))
{
if(validAge(age, "AGE MUST BE A NUMERIC VALUE"))
{
if(notEmpty(email, "ENTER EMAIL"))
{
if(emailValid(email, "ENTER A PROPER EMAIL ADDRESS"))
{
return emailValid();
}
}
}
}
}
}
return false;
}

function notEmpty(elem, helperMsg)
{
if(elem.value.length == 0)
{
alert(helperMsg);
elem.focus();
return false;
}

return true;
}

function validAge(elem, helperMsg)
{
var age = elem.value;

if(age 100 || age.type == string???))
{
alert(helperMsg);
return false;
}

return true;
}

function emailValid(elem, helperMsg)
{
var atpos = elem.value.indexOf(“@”);
var dotpos = elem.value.lastIndexOf(“.”);

if(atpos < 0 || dotpos

Firstname:
Surname:
Age:
Email: