richyrich38
07-24-2009, 10:19 AM
HI Guys, not the greatest with javascript
I have this form validation code
function check_email(mailstring)
{
valid = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
for(i=0; i < mailstring.length ;i++)
{
if (valid.indexOf(mailstring.charAt(i))<0)
{
return (false);
}
}
if (document.images)
{
one = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
if (!mailstring.match(one) && mailstring.match(two))
{
return (-1);
}
}
}
function validate()
{
if (document.mailpage.contact_name.value=="")
{
alert("Name not entered")
return false
}
if (document.mailpage.contact_address.value=="")
{
alert("Address not entered")
return false
}
if (document.mailpage.contact_otherinfo.value=="")
{
alert("Operational Details / Other Information was not entered")
return false
}
if (!check_email(document.mailpage.contact_email.value))
{
alert("Invalid Email address")
return false
}
if (document.mailpage.contact_phone.value=="")
{
alert("Phone not entered")
return false
}
}
at the moment its checks that someting has been enetered in all these fields,
what would be the best way to check that the email or phone nummber had been entered?? will not send if nothing enetered, but will send if one or both have been enetered?
I have this form validation code
function check_email(mailstring)
{
valid = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
for(i=0; i < mailstring.length ;i++)
{
if (valid.indexOf(mailstring.charAt(i))<0)
{
return (false);
}
}
if (document.images)
{
one = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
if (!mailstring.match(one) && mailstring.match(two))
{
return (-1);
}
}
}
function validate()
{
if (document.mailpage.contact_name.value=="")
{
alert("Name not entered")
return false
}
if (document.mailpage.contact_address.value=="")
{
alert("Address not entered")
return false
}
if (document.mailpage.contact_otherinfo.value=="")
{
alert("Operational Details / Other Information was not entered")
return false
}
if (!check_email(document.mailpage.contact_email.value))
{
alert("Invalid Email address")
return false
}
if (document.mailpage.contact_phone.value=="")
{
alert("Phone not entered")
return false
}
}
at the moment its checks that someting has been enetered in all these fields,
what would be the best way to check that the email or phone nummber had been entered?? will not send if nothing enetered, but will send if one or both have been enetered?