NameSilo

Form Validation Help!!!

Spacemail by SpaceshipSpacemail by Spaceship
Watch

noswad

Established Member
Impact
1
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:

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:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
EDIT: Nvmd, didn't work.. :/
 
Last edited:
0
•••
Im not sure i know you can do it in php like:
PHP:
if (isset($_POST['submit']) && !empty($_POST['usernmae']))
{
echo "blah";
}
 
0
•••
Hi

Thanks for trying but I can't get it working.

Anyone else? Im sure they're must be a simple bit of JAVA i just add in?!

Cheers guys.
 
0
•••

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back