Hey guys I know there is a similar post on here but it didn't really give me any actual help on this topic:
It seems that I have the correct regular expressions in this however it doesn't want to follow my freaking instructions can you guys maybe show me where I'm going wrong and give me a short source code on how to rectify it. Code is below:
function validate(theForm)
{
var falseCounter = 0;
var firstName = theForm.first_name.value;
var lastName = theForm.last_name.value;
var mail = theForm.email.value;
var phoneNum = theForm.phone.value;
var suburbs = theForm.suburb.value;
var cities = theForm.city.value;
var counties = theForm.country;
var alphaTest = /^([A-Za-z+]\s)|([A-Za-z+]\s-\s[A-Za-z+]\s)$/;
var emailTest = /(^[\w+]|[\w+.w+]@[\w+\.\w+]$)/;
var numTest = /(^[00|0|+][\d+]$)/;
if (alphaTest.test(firstName))
{
return true;
}
else
{
alert("Invalid name format.");
return false;
falseCounter ++;
}
if (alphaTest.test(lastName))
{
return true;
}
else
{
alert("Invalid name format.");
return false;
falseCounter ++;
}
if (emailTest.test(mail))
{
return true;
}
else
{
alert("Not a valid email address");
return false;
falseCounter ++;
}
if (numTest.test(phoneNum))
{
return true;}
else
{
falseCounter ++;
alert("Not a valid phone number.");
}
if (alphaTest.test(suburbs))
{;
return true;
}
else
{
falseCounter ++;
alert("Invalid area format.");
}
if (alphaTest.test(cities))
{;
return true;
}
else
{
falseCounter ++;
alert("Invalid area format.");
}
if (countries == "")
{
falseCounter++;
alert("CHOOSE A FUCKING COUNTRY");
}
else
{
return true;
}
if (falseCounter > 0)
{
return false;
}
else
{
return true;
}
}
This is in a separate .js file. basically i want it to return which areas are false in an alert (for now, at a later stage I will have to make the mark up change when this section is incorrectly completed) and then have a false counter to allow whether or not it can post because the way I had it was returning a single false/true test through alphaTest.test(firstName) which only checked if that was right and didn't care about the other ones