Hi.
I use the following javascript (see below) so that if a field in my form is left blank an error message pops up.
However, I would like to extend this so that for example...
If the field username contains '-' or '_' or '!' etc an error message pops up. I simply want valid characters to be numbers and letters only (except the email address field). Nothing else.
My code I have at the mo is this:
Can anyone help please?
I use the following javascript (see below) so that if a field in my form is left blank an error message pops up.
However, I would like to extend this so that for example...
If the field username contains '-' or '_' or '!' etc an error message pops up. I simply want valid characters to be numbers and letters only (except the email address field). Nothing else.
My code I have at the mo is this:
PHP:
<script Language="JavaScript">
<!--
function Form1_Validator(theForm)
{
if (theForm.username.value == "")
{
alert("Please enter a username");
theForm.username.focus();
return (false);
}
if (theForm.email.value == "")
{
alert("Please enter an email address");
theForm.email.focus();
return (false);
}
if (theForm.password.value == "")
{
alert("Please choose a password");
theForm.password.focus();
return (false);
}
if (theForm.password.value != theForm.confirm.value)
{
alert("The two passwords are not the same.");
theForm.confirm.focus();
return (false);
}
if (theForm.gift.value == "")
{
alert("Please choose a mobile phone!");
theForm.gift.focus();
return (false);
}
if (theForm.address.value == "")
{
alert("Please enter a delivery name and address");
theForm.address.focus();
return (false);
}
}
</script>
Can anyone help please?
Last edited:






