Hi guys,

I seem to have come across a weird issue in internet explorer.
I've been working on doing regular expressions for a register form, and I've checked it in Firefox, and Chrome and it seems to work for both of them but yet it doesn't work for Internext Explorer 6 - 8.

The issue is that the drop down boxes (select fields) dont seem to be recognised for RegEx in I.E. this is causing an issue for me as I want it to work in ALL common web browers as well as keeping the whole form standard.

I've pasted a snippet of code below to show you what I've done.

This one below is the original one which just checks if the field entry is blank

function check(theForm)
{
	var checker;

	//  Select fields alternate test
	var day = theForm.day.value;
	var month = theForm.month.value;
	var year = theForm.year.value;
	var gender = theForm.gender.value;

	// Gets all label and div tag fields into a variable fo testing later
	var age = document.getElementById('userAge');
	var userGender = document.getElementById('userGender');


        if (day == "")
	{
		var adder = age.innerHTML + "";
		adder = '<label class="incorrect" id="userAge"> *Date Of birth*: </label>';
		age.innerHTML = adder;
		checker = false;
	}
	else if (month == "")
	{
		var adder = age.innerHTML + "";
		adder = '<label class="incorrect" id="userAge"> *Date Of birth*: </label>';
		age.innerHTML = adder;
		checker = false;
	}
	else if (year == "")
	{
		var adder = age.innerHTML + "";
		adder = '<label class="incorrect" id="userAge"> *Date Of birth*: </label>';
		age.innerHTML = adder;
		checker = false;
	}
	else
	{
		var adder = age.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="loginLabel" id="userAge"> Date Of birth: </label>'; // changes the current div tag into the innerHTML field
		age.innerHTML = adder; // changes the innerHTML to equal the adder
	}
	
	if (gender == "")
	{
		var adder = userGender.innerHTML + "";
		adder = '<label class="incorrect" id="userGender"> *Gender*: </label>';
		userGender.innerHTML = adder;
		checker = false;
	}
	else
	{
		var adder = userGender.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="loginLabel" id="userGender"> Gender: </label>'; // changes the current div tag into the innerHTML field
		userGender.innerHTML = adder; // changes the innerHTML to equal the adder
	}
	
}

This next one is an actual regular expression test using 2 methods which work on all other fields I have in the form (And also I tested them in FF and Chrome)

function check(theForm)
{
	var checker;

	//  Select fields alternate test
	var day = theForm.day.value;
	var month = theForm.month.value;
	var year = theForm.year.value;
	var gender = theForm.gender.value;

	// Gets all label and div tag fields into a variable fo testing later
	var age = document.getElementById('userAge');
	var userGender = document.getElementById('userGender');

        var letterTest = /(^[A-Z|a-z\s]+$)/; // checks to see if the letters are the only entry (or if its blank)
        var numberTest = /([0-9]+$)/; // ensures that there is at least one number in the field

	if (numberTest.test(day) == false)
	{
		var adder = age.innerHTML + "";
		adder = '<label class="incorrect" id="userAge"> *Date Of birth*: </label>';
		age.innerHTML = adder;
		checker = false;
	}
	else if (letterTest.test(month) == false)
	{
		var adder = age.innerHTML + "";
		adder = '<label class="incorrect" id="userAge"> *Date Of birth*: </label>';
		age.innerHTML = adder;
		checker = false;
	}
	else if (numberTest.test(year) == false)
	{
		var adder = age.innerHTML + "";
		adder = '<label class="incorrect" id="userAge"> *Date Of birth*: </label>';
		age.innerHTML = adder;
		checker = false;
	}
	else
	{
		var adder = age.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="loginLabel" id="userAge"> Date Of birth: </label>'; // changes the current div tag into the innerHTML field
		age.innerHTML = adder; // changes the innerHTML to equal the adder
	}
	
	if (letterTest.test(gender) == false)
	{
		var adder = userGender.innerHTML + "";
		adder = '<label class="incorrect" id="userGender"> *Gender*: </label>';
		userGender.innerHTML = adder;
		checker = false;
	}
	else
	{
		var adder = userGender.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="loginLabel" id="userGender"> Gender: </label>'; // changes the current div tag into the innerHTML field
		userGender.innerHTML = adder; // changes the innerHTML to equal the adder
	}
	
}

If you have any Ideas about what I can do to make it work in I.E. I would be most greatful. Also if anyone knows how to do and RegEx on a checkbox that would help me quite a bit too.


Thanks in advance,
Your Freidnly Neighbourhood,

Ghost

what is html code of drop down boxes?
you need to give value to option tag e.g.

<option value="2200">2200</option>

what is html code of drop down boxes?

Hey,

I have set the "selected" to

<option selected="selected"> </option>

and the given other options of

<option> January </option>

I haven't done the values yet. However if that is the cause (which I will inform tomorrow about as it is quite late, I thank you and slap myself for stupidity.

Okay.. check later and post result.

Hey man,

Thanks that work 100%
Do you have any idea what to do for a checkbox?

I've used the following:

1. uses regular expressions to test if the value "isChecked" comes into the variable

function check(theForm)
{
	
	var checker;

	// Check box alternate test
	var checkBox = theForm.tacBox.value;

	var myCheckBox = document.getElementById('mustCheck');
	
	var letterTest = /(^[A-Z|a-z\s]+$)/; // checks to see if the letters are the only entry (or if its blank)


	if (letterTest.test(checkBox) == false)
	{
		var adder = myCheckBox.innerHTML + "";
		adder = '<div id="incorrect"> ***YOU MUST ACCEPT THE TERMS AND CONDITIONS*** </div>';
		myCheckBox.innerHTML = adder;
		checker = false;
	}
	else
	{
		var adder = myCheckBox.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<div id="mustCheck"> </div>'; // changes the current div tag into the innerHTML field
		myCheckBox.innerHTML = adder; // changes the innerHTML to equal the adder
	}
}

AND

2. uses the javascript capability of checking if a box is checked through the ID

function check(theForm)
{
	
	var checker;

	var checkbox = document.getElementById("tacBox");

	if (checkbox.checked)
	{
		var adder = myCheckBox.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<div id="mustCheck"> </div>'; // changes the current div tag into the innerHTML field
		myCheckBox.innerHTML = adder; // changes the innerHTML to equal the adder
	}
	else
	{
		var adder = myCheckBox.innerHTML + "";
		adder = '<div id="incorrect"> ***YOU MUST ACCEPT THE TERMS AND CONDITIONS*** </div>';
		myCheckBox.innerHTML = adder;
		checker = false;		
	}
}

Thanks again in advance

Second approach is good. BTW m not MAN, m MISS :)

hi this is shine OS I am frequently getting browser compatibility problems with ie 7 please help me

Hey soz about that lol, In my country its just a general greating short for Human... lol not like we say huwoman...

But yea neither of my two approches seem to work

hi this is shine OS I am frequently getting browser compatibility problems with ie 7 please help me

Bro you need to say what the issue is and what you have done

check this code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript">
function check(theForm)
{
	
	var checker;
	var checkbox = document.getElementById("tacBox");
	if (checkbox.checked)
	{
		document.getElementById("myCheckBox").innerHTML = '<div id="mustCheck"> </div>';; // changes the innerHTML to equal the adder
		checker = true;		
	}
	else
	{
		document.getElementById("myCheckBox").innerHTML = '<div id="incorrect"> ***YOU MUST ACCEPT THE TERMS AND CONDITIONS*** </div>';		
		checker = false;		
	}
	return checker;
}
</script>
</head>

<body>
<form name="form" id="form" onsubmit="return check(this);" >
<input id="tacBox" name="tacBox" type="checkbox" value="1" /> check box

<span id="myCheckBox"></span>
<input name="submit" value="submit" type="submit" />
</form>
</body>
</html>

hey thanks alot yea I got it... I forgot to insert a line of code
which edited the section of "mustCheck"

This is the following code that I have which works 100%

regEx.js

function check(theForm)
{
	//=======================================================================
	//			Variables to check correct issuement later
	//=======================================================================
	var checker;
	var pwLen;
		
		
	//=======================================================================
	//						Field Validation
	//=======================================================================
	
	//Input fields generic test
	var firstName = theForm.firstName.value;
	var lastName = theForm.lastName.value;
	var userName = theForm.userName.value;
	var userPass = theForm.password_reg.value;
	var confUserPass = theForm.confPassword.value;
	var email = theForm.email_reg.value;
	var confEmail = theForm.confEmail.value;
	
	//  Select fields alternate test
	var day = theForm.day.value;
	var month = theForm.month.value;
	var year = theForm.year.value;
	var gender = theForm.gender.value;

	// Check box alternate test for if checked
	var checkbox = document.getElementById("tacBox");
	
	
	//=========================================================================
	//						Variablising of text elements
	//=========================================================================
	
	// Gets all label and div tag fields into a variable fo testing later
	var first_name = document.getElementById('userFirstName');
	var last_name = document.getElementById('userLastName');
	var username = document.getElementById('usersName');
	var pw = document.getElementById('userPass');
	var confPw = document.getElementById('userConfPass');
	var mail = document.getElementById('userEmail');
	var confMail = document.getElementById('userConfEmail');
	var age = document.getElementById('userAge');
	var userGender = document.getElementById('userGender');
	
	var myCheckBox = document.getElementById('mustCheck');
	
		
	//=========================================================================
	//						Regular Expression test to ensure the 
	//						denoted input fields have propper text
	//=========================================================================
	var letterTest = /(^[A-Z|a-z\s]+$)/; // checks to see if the letters are the only entry (or if its blank)
	var pwTest = /([A-Za-z0-9._-]{6,})/; //checks too see if the password has any of these and matches 6 letters or more
	var emailTest = /^[a-zA-Z0-9._+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; //checks to see if its a valid email address	
	
	
	if (letterTest.test(firstName) == false)
	{
		var adder = first_name.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="incorrect" id="userFirstName"> *First Name*: </label>'; // changes the current label tag into the innerHTML field
		first_name.innerHTML = adder; // changes the innerHTML to equal the adder
		checker = false; // checker becomes false and needs to show the user
	}
	else
	{
		var adder = first_name.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="loginLabel" id="userFirstName"> First Name: </label>'; // changes the current label tag into the innerHTML field
		first_name.innerHTML = adder; // changes the innerHTML to equal the adder
	}
	
	if (letterTest.test(lastName) == false)
	{
		var adder = last_name.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="incorrect" id="userLastName"> *Last Name*: </label>'; // changes the current label tag into the innerHTML field
		last_name.innerHTML = adder; // changes the innerHTML to equal the adder
		checker = false; // checker becomes false and needs to show the user
	}
	else
	{
		var adder = last_name.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="loginLabel" id="userLastName"> Last Name: </label>'; // changes the current label tag into the innerHTML field
		last_name.innerHTML = adder; // changes the innerHTML to equal the adder
	}
	
	if (letterTest.test(userName) == false)
	{
		var adder = username.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="incorrect" id="usersName"> *User Name*: </label>'; // changes the current label tag into the innerHTML field
		username.innerHTML = adder; // changes the innerHTML to equal the adder
		checker = false; // checker becomes false and needs to show the user
	}
	else
	{
		var adder = username.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="loginLabel" id="usersName"> User Name: </label>'; // changes the current label tag into the innerHTML field
		username.innerHTML = adder; // changes the innerHTML to equal the adder
	}
	
	if (pwTest.test(userPass) == false)
	{
		var adder = pw.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="incorrect" id="userPass"> *Password*: </label>'; // changes the current label tag into the innerHTML field
		pw.innerHTML = adder; // changes the innerHTML to equal the adder
		pwLen = false; // checker becomes false and needs to show the user
	}
	else
	{
		var adder = pw.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="loginLabel" id="userPass"> Password: </label>'; // changes the current label tag into the innerHTML field
		pw.innerHTML = adder; // changes the innerHTML to equal the adder
	} 
	
	if ((pwTest.test(confUserPass) == true) && (confUserPass == userPass))
	{
		var adder = confPw.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="loginLabel" id="userConfPass"> Confirm Password: </label>'; // changes the current label tag into the innerHTML field
		confPw.innerHTML = adder; // changes the innerHTML to equal the adder		
	}
	else
	{
		var adder = confPw.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="incorrect" id="userConfPass"> *Confirm Password*: </label>'; // changes the current label tag into the innerHTML field
		confPw.innerHTML = adder; // changes the innerHTML to equal the adder
		pwLen = false; // checker becomes false and needs to show the user
	}
	
	if (emailTest.test(email) == false)
	{
		var adder = mail.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="incorrect" id="userEmail"> *Email*: </label>'; // changes the current label tag into the innerHTML field
		mail.innerHTML = adder; // changes the innerHTML to equal the adder
		checker = false; // checker becomes false and needs to show the user
	}
	else
	{
		var adder = mail.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="loginLabel" id="userEmail"> Email: </label>'; // changes the current label tag into the innerHTML field
		mail.innerHTML = adder; // changes the innerHTML to equal the adder
	}
	
	if ((emailTest.test(confEmail) == true )&& (confEmail == email))
	{
		var adder = confMail.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="loginLabel" id="userConfEmail"> Confirm Email: </label>'; // changes the current label tag into the innerHTML field
		confMail.innerHTML = adder; // changes the innerHTML to equal the adder
	}
	else
	{
		var adder = confMail.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="incorrect" id="userConfEmail"> *Confirm Email*: </label>'; // changes the current label tag into the innerHTML field
		confMail.innerHTML = adder; // changes the innerHTML to equal the adder
		checker = false; // checker becomes false and needs to show the user
	}
	
	if (day == "")
	{
		var adder = age.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="incorrect" id="userAge"> *Date Of birth*: </label>'; // changes the current label tag into the innerHTML field
		age.innerHTML = adder; // changes the innerHTML to equal the adder
		checker = false; // checker becomes false and needs to show the user
	}
	else if (month == "")
	{
		var adder = age.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="incorrect" id="userAge"> *Date Of birth*: </label>'; // changes the current label tag into the innerHTML field
		age.innerHTML = adder; // changes the innerHTML to equal the adder
		checker = false; // checker becomes false and needs to show the user
	}
	else if (year == "")
	{
		var adder = age.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="incorrect" id="userAge"> *Date Of birth*: </label>'; // changes the current label tag into the innerHTML field
		age.innerHTML = adder; // changes the innerHTML to equal the adder
		checker = false; // checker becomes false and needs to show the user
	}
	else
	{
		var adder = age.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="loginLabel" id="userAge"> Date Of birth: </label>'; // changes the current label tag into the innerHTML field
		age.innerHTML = adder; // changes the innerHTML to equal the adder
	}
	
	if (gender == "")
	{
		var adder = userGender.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="incorrect" id="userGender"> *Gender*: </label>'; // changes the current label tag into the innerHTML field
		userGender.innerHTML = adder; // changes the innerHTML to equal the adder
		checker = false; // checker becomes false and needs to show the user
	}
	else
	{
		var adder = userGender.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="loginLabel" id="userGender"> Gender: </label>'; // changes the current label tag into the innerHTML field
		userGender.innerHTML = adder; // changes the innerHTML to equal the adder
	}
	
	
	if (checkbox.checked)
	{
		var adder = myCheckBox.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<div id="mustCheck"> </div>'; // changes the current div tag into the innerHTML field
		myCheckBox.innerHTML = adder; // changes the innerHTML to equal the adder
	}
	else
	{
		var adder = myCheckBox.innerHTML + "";
		adder = '<div id="mustCheck" class="incorrect"> ***YOU MUST ACCEPT THE TERMS AND CONDITIONS*** </div>';
		myCheckBox.innerHTML = adder;
		checker = false;		
	}
	
	// see if the user has false or true contact details... if false
	if (checker == false)
	{
		alert("You have 1 or more incorrect fields. Please correct them now!"); // let them know that they have inccorect fields
		return false; // make the onsumbit false
	}	
	else if (pwLen == false)
	{
		alert("Please retype your password. It does not fit the proper criteria!");
		return false;
	}
	
}

form

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>


<script language="javascript" type="text/javascript" src="regEx.js" defer="defer"></script>

<form action="#######.php" enctype="application/x-www-form-urlencoded" method="post" onsubmit="return check(this)" target="_self" name="register" id="register">
   <table width="483" border="auto" style="border:thick; background-color:#FFF" bordercolor="#000000">
      <tr>
         <td width="477" height="327">
              <h2 align="center">Sign Up </h2>
                                     
                   <table width="440"> 
           		<tr>
                          <td width="183" align="right">
                              <label class="loginLabel" id="userFirstName"> First Name: </label>
                         </td>
                         <td width="285" align="left">
                              <input type="text" class="loginInput" name="firstName" id="firstName" tabindex="4">
                          </td>
                      </tr>
                      <tr>
                          <td align="right">
                              <label class="loginLabel" id="userLastName"> Last Name: </label>
                          </td>
                          <td align="left">
                              <input type="text" class="loginInput" name="lastName" id="lastName" tabindex="5" />
                          </td>
                      </tr>
                      <tr>
                          <td align="right">
                              <label class="loginLabel" id="usersName"> User Name: </label>
                          </td>
                          <td align="left">
                              <input type="text" class="loginInput" name="userName" id="userName" tabindex="6">
                          </td>
                      </tr>
                      <tr>
                          <td align="right">
                              <label class="loginLabel" id="userPass"> Password: </label>
                          </td>
                          <td align="left">
                              <input type="password" class="loginInput" name="password_reg" id="password_reg" tabindex="7">
                          </td>
                      </tr>
                      <tr>
                          <td align="right">
                              <label class="loginLabel" id="userConfPass"> Confirm Password: </label>
                          </td>
                          <td align="left">
                              <input type="password" class="loginInput" name="confPassword" id="confPassword" tabindex="8">
                           </td>
                       </tr>
                       <tr>
                           <td align="right">
                               <label class="loginLabel" id="userEmail"> Email: </label>
                           </td>
                           <td align="left">
                               <input type="text" class="loginInput" name="email_reg" id="email_reg" tabindex="9">
                           </td>
                       </tr>
                       <tr>
                           <td align="right">
                               <label class="loginLabel" id="userConfEmail"> Confirm Email: </label>
                           </td>
                           <td align="left">
                              <input type="text" class="loginInput" name="confEmail" id="confEmail" tabindex="10">
                           </td>
                       </tr>
                       <tr>
                           <td height="56" align="right">
                                <label class="loginLabel" id="userAge"> Date Of birth: </label>
                           </td>
                           <td align="left">
                               <select name="day" id="day" tabindex="11">
                                   <option value="" selected="selected"> </option>
                                   <option value="01"> 01 </option>
                                   <option value="02"> 02 </option>
                                   <option value="03"> 03 </option>
                                   <option value="04"> 04 </option>
                                   <option value="05"> 05 </option>
                                   <option value="06"> 06 </option>
                                   <option value="07"> 07 </option>
                                   <option value="08"> 08 </option>
                                   <option value="09"> 09 </option>
                                   <option value="10"> 10 </option>
                                   <option value="11"> 11 </option>
                                   <option value="12"> 12 </option>
                                   <option value="13"> 13 </option>
                                   <option value="14"> 14 </option>
                                   <option value="15"> 15 </option>
                                   <option value="16"> 16 </option>
                                   <option value="17"> 17 </option>
                                   <option value="18"> 18 </option>
                                   <option value="19"> 19 </option>
                                   <option value="20"> 20 </option>
                                   <option value="21"> 21 </option>
                                   <option value="22"> 22 </option>
                                   <option value="23"> 23 </option>
                                   <option value="24"> 24 </option>
                                   <option value="25"> 25 </option>
                                   <option value="26"> 26 </option>
                                   <option value="27"> 27 </option>
                                   <option value="28"> 28 </option>
                                   <option value="29"> 29 </option>
                                   <option value="30"> 30 </option>
                                   <option value="31"> 31 </option>               
                               </select>
                               <select name="month" id="month" tabindex="12">
                                   <option value="" selected="selected"> </option>
                                   <option value="January"> January </option>
                                   <option value="February"> February </option>
                                   <option value="March"> March </option>
                                   <option value="April"> April </option>
                                   <option value="May"> May </option>
                                   <option value="June"> June </option>
                                   <option value="July"> July </option>
                                   <option value="August"> August </option>
                                   <option value="September"> September </option>
                                   <option value="October"> October </option>
                                   <option value="November"> November </option>
                                   <option value="December"> December </option>
                               </select>
                               <select name="year" id="year" tabindex="13">
                                   <option value="" selected="selected"> </option>
                                   <option value="1990"> 1990 </option>
                                   <option value="1991"> 1991 </option>
                               </select>
                            </td>
                        </tr>
                        <tr>
                            <td height="46" align="right"> 
                                <label class="loginLabel" id="userGender"> Gender </label>
                            </td>
                            <td align="left">
                                <select name="gender" id="gender" tabindex="14">
                                   <option value="" selected="selected"> </option>
                                   <option value="Male"> Male </option>
                                   <option value="Female"> Female </option>
                                </select>
                            </td>
                        </tr>
                     </table>
    
                     <div id="mustCheck"> </div>
                     <div align="center">
                     	  <label class="loginLabel" style="margin-top:1em; margin-bottom:1em;" id="tAndC"> 
                          <br />
                          I Agree To <a href="#">Terms And Conditions</a> Of Use 
                          </label>

                          <input type="checkbox" name="tacBox" id="tacBox" value="isChecked" tabindex="15">
                          <br />
                          <br />
                          <input name="signUp" type="submit" value="Sign Up" />
                      </div>

                  </td>
	      </tr>
         </table>
				
     </form>

hey thanks alot yea I got it... I forgot to insert a line of code
which edited the section of "mustCheck"

This is the following code that I have which works 100%

regEx.js

function check(theForm)
{
	//=======================================================================
	//			Variables to check correct issuement later
	//=======================================================================
	var checker;
	var pwLen;
		
		
	//=======================================================================
	//						Field Validation
	//=======================================================================
	
	//Input fields generic test
	var firstName = theForm.firstName.value;
	var lastName = theForm.lastName.value;
	var userName = theForm.userName.value;
	var userPass = theForm.password_reg.value;
	var confUserPass = theForm.confPassword.value;
	var email = theForm.email_reg.value;
	var confEmail = theForm.confEmail.value;
	
	//  Select fields alternate test
	var day = theForm.day.value;
	var month = theForm.month.value;
	var year = theForm.year.value;
	var gender = theForm.gender.value;

	// Check box alternate test for if checked
	var checkbox = document.getElementById("tacBox");
	
	
	//=========================================================================
	//						Variablising of text elements
	//=========================================================================
	
	// Gets all label and div tag fields into a variable fo testing later
	var first_name = document.getElementById('userFirstName');
	var last_name = document.getElementById('userLastName');
	var username = document.getElementById('usersName');
	var pw = document.getElementById('userPass');
	var confPw = document.getElementById('userConfPass');
	var mail = document.getElementById('userEmail');
	var confMail = document.getElementById('userConfEmail');
	var age = document.getElementById('userAge');
	var userGender = document.getElementById('userGender');
	
	var myCheckBox = document.getElementById('mustCheck');
	
		
	//=========================================================================
	//						Regular Expression test to ensure the 
	//						denoted input fields have propper text
	//=========================================================================
	var letterTest = /(^[A-Z|a-z\s]+$)/; // checks to see if the letters are the only entry (or if its blank)
	var pwTest = /([A-Za-z0-9._-]{6,})/; //checks too see if the password has any of these and matches 6 letters or more
	var emailTest = /^[a-zA-Z0-9._+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; //checks to see if its a valid email address	
	
	
	if (letterTest.test(firstName) == false)
	{
		var adder = first_name.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="incorrect" id="userFirstName"> *First Name*: </label>'; // changes the current label tag into the innerHTML field
		first_name.innerHTML = adder; // changes the innerHTML to equal the adder
		checker = false; // checker becomes false and needs to show the user
	}
	else
	{
		var adder = first_name.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="loginLabel" id="userFirstName"> First Name: </label>'; // changes the current label tag into the innerHTML field
		first_name.innerHTML = adder; // changes the innerHTML to equal the adder
	}
	
	if (letterTest.test(lastName) == false)
	{
		var adder = last_name.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="incorrect" id="userLastName"> *Last Name*: </label>'; // changes the current label tag into the innerHTML field
		last_name.innerHTML = adder; // changes the innerHTML to equal the adder
		checker = false; // checker becomes false and needs to show the user
	}
	else
	{
		var adder = last_name.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="loginLabel" id="userLastName"> Last Name: </label>'; // changes the current label tag into the innerHTML field
		last_name.innerHTML = adder; // changes the innerHTML to equal the adder
	}
	
	if (letterTest.test(userName) == false)
	{
		var adder = username.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="incorrect" id="usersName"> *User Name*: </label>'; // changes the current label tag into the innerHTML field
		username.innerHTML = adder; // changes the innerHTML to equal the adder
		checker = false; // checker becomes false and needs to show the user
	}
	else
	{
		var adder = username.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="loginLabel" id="usersName"> User Name: </label>'; // changes the current label tag into the innerHTML field
		username.innerHTML = adder; // changes the innerHTML to equal the adder
	}
	
	if (pwTest.test(userPass) == false)
	{
		var adder = pw.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="incorrect" id="userPass"> *Password*: </label>'; // changes the current label tag into the innerHTML field
		pw.innerHTML = adder; // changes the innerHTML to equal the adder
		pwLen = false; // checker becomes false and needs to show the user
	}
	else
	{
		var adder = pw.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="loginLabel" id="userPass"> Password: </label>'; // changes the current label tag into the innerHTML field
		pw.innerHTML = adder; // changes the innerHTML to equal the adder
	} 
	
	if ((pwTest.test(confUserPass) == true) && (confUserPass == userPass))
	{
		var adder = confPw.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="loginLabel" id="userConfPass"> Confirm Password: </label>'; // changes the current label tag into the innerHTML field
		confPw.innerHTML = adder; // changes the innerHTML to equal the adder		
	}
	else
	{
		var adder = confPw.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="incorrect" id="userConfPass"> *Confirm Password*: </label>'; // changes the current label tag into the innerHTML field
		confPw.innerHTML = adder; // changes the innerHTML to equal the adder
		pwLen = false; // checker becomes false and needs to show the user
	}
	
	if (emailTest.test(email) == false)
	{
		var adder = mail.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="incorrect" id="userEmail"> *Email*: </label>'; // changes the current label tag into the innerHTML field
		mail.innerHTML = adder; // changes the innerHTML to equal the adder
		checker = false; // checker becomes false and needs to show the user
	}
	else
	{
		var adder = mail.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="loginLabel" id="userEmail"> Email: </label>'; // changes the current label tag into the innerHTML field
		mail.innerHTML = adder; // changes the innerHTML to equal the adder
	}
	
	if ((emailTest.test(confEmail) == true )&& (confEmail == email))
	{
		var adder = confMail.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="loginLabel" id="userConfEmail"> Confirm Email: </label>'; // changes the current label tag into the innerHTML field
		confMail.innerHTML = adder; // changes the innerHTML to equal the adder
	}
	else
	{
		var adder = confMail.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="incorrect" id="userConfEmail"> *Confirm Email*: </label>'; // changes the current label tag into the innerHTML field
		confMail.innerHTML = adder; // changes the innerHTML to equal the adder
		checker = false; // checker becomes false and needs to show the user
	}
	
	if (day == "")
	{
		var adder = age.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="incorrect" id="userAge"> *Date Of birth*: </label>'; // changes the current label tag into the innerHTML field
		age.innerHTML = adder; // changes the innerHTML to equal the adder
		checker = false; // checker becomes false and needs to show the user
	}
	else if (month == "")
	{
		var adder = age.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="incorrect" id="userAge"> *Date Of birth*: </label>'; // changes the current label tag into the innerHTML field
		age.innerHTML = adder; // changes the innerHTML to equal the adder
		checker = false; // checker becomes false and needs to show the user
	}
	else if (year == "")
	{
		var adder = age.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="incorrect" id="userAge"> *Date Of birth*: </label>'; // changes the current label tag into the innerHTML field
		age.innerHTML = adder; // changes the innerHTML to equal the adder
		checker = false; // checker becomes false and needs to show the user
	}
	else
	{
		var adder = age.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="loginLabel" id="userAge"> Date Of birth: </label>'; // changes the current label tag into the innerHTML field
		age.innerHTML = adder; // changes the innerHTML to equal the adder
	}
	
	if (gender == "")
	{
		var adder = userGender.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="incorrect" id="userGender"> *Gender*: </label>'; // changes the current label tag into the innerHTML field
		userGender.innerHTML = adder; // changes the innerHTML to equal the adder
		checker = false; // checker becomes false and needs to show the user
	}
	else
	{
		var adder = userGender.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<label class="loginLabel" id="userGender"> Gender: </label>'; // changes the current label tag into the innerHTML field
		userGender.innerHTML = adder; // changes the innerHTML to equal the adder
	}
	
	
	if (checkbox.checked)
	{
		var adder = myCheckBox.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
		adder = '<div id="mustCheck"> </div>'; // changes the current div tag into the innerHTML field
		myCheckBox.innerHTML = adder; // changes the innerHTML to equal the adder
	}
	else
	{
		var adder = myCheckBox.innerHTML + "";
		adder = '<div id="mustCheck" class="incorrect"> ***YOU MUST ACCEPT THE TERMS AND CONDITIONS*** </div>';
		myCheckBox.innerHTML = adder;
		checker = false;		
	}
	
	// see if the user has false or true contact details... if false
	if (checker == false)
	{
		alert("You have 1 or more incorrect fields. Please correct them now!"); // let them know that they have inccorect fields
		return false; // make the onsumbit false
	}	
	else if (pwLen == false)
	{
		alert("Please retype your password. It does not fit the proper criteria!");
		return false;
	}
	
}

form

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>


<script language="javascript" type="text/javascript" src="regEx.js" defer="defer"></script>

<form action="#######.php" enctype="application/x-www-form-urlencoded" method="post" onsubmit="return check(this)" target="_self" name="register" id="register">
   <table width="483" border="auto" style="border:thick; background-color:#FFF" bordercolor="#000000">
      <tr>
         <td width="477" height="327">
              <h2 align="center">Sign Up </h2>
                                     
                   <table width="440"> 
           		<tr>
                          <td width="183" align="right">
                              <label class="loginLabel" id="userFirstName"> First Name: </label>
                         </td>
                         <td width="285" align="left">
                              <input type="text" class="loginInput" name="firstName" id="firstName" tabindex="4">
                          </td>
                      </tr>
                      <tr>
                          <td align="right">
                              <label class="loginLabel" id="userLastName"> Last Name: </label>
                          </td>
                          <td align="left">
                              <input type="text" class="loginInput" name="lastName" id="lastName" tabindex="5" />
                          </td>
                      </tr>
                      <tr>
                          <td align="right">
                              <label class="loginLabel" id="usersName"> User Name: </label>
                          </td>
                          <td align="left">
                              <input type="text" class="loginInput" name="userName" id="userName" tabindex="6">
                          </td>
                      </tr>
                      <tr>
                          <td align="right">
                              <label class="loginLabel" id="userPass"> Password: </label>
                          </td>
                          <td align="left">
                              <input type="password" class="loginInput" name="password_reg" id="password_reg" tabindex="7">
                          </td>
                      </tr>
                      <tr>
                          <td align="right">
                              <label class="loginLabel" id="userConfPass"> Confirm Password: </label>
                          </td>
                          <td align="left">
                              <input type="password" class="loginInput" name="confPassword" id="confPassword" tabindex="8">
                           </td>
                       </tr>
                       <tr>
                           <td align="right">
                               <label class="loginLabel" id="userEmail"> Email: </label>
                           </td>
                           <td align="left">
                               <input type="text" class="loginInput" name="email_reg" id="email_reg" tabindex="9">
                           </td>
                       </tr>
                       <tr>
                           <td align="right">
                               <label class="loginLabel" id="userConfEmail"> Confirm Email: </label>
                           </td>
                           <td align="left">
                              <input type="text" class="loginInput" name="confEmail" id="confEmail" tabindex="10">
                           </td>
                       </tr>
                       <tr>
                           <td height="56" align="right">
                                <label class="loginLabel" id="userAge"> Date Of birth: </label>
                           </td>
                           <td align="left">
                               <select name="day" id="day" tabindex="11">
                                   <option value="" selected="selected"> </option>
                                   <option value="01"> 01 </option>
                                   <option value="02"> 02 </option>
                                   <option value="03"> 03 </option>
                                   <option value="04"> 04 </option>
                                   <option value="05"> 05 </option>
                                   <option value="06"> 06 </option>
                                   <option value="07"> 07 </option>
                                   <option value="08"> 08 </option>
                                   <option value="09"> 09 </option>
                                   <option value="10"> 10 </option>
                                   <option value="11"> 11 </option>
                                   <option value="12"> 12 </option>
                                   <option value="13"> 13 </option>
                                   <option value="14"> 14 </option>
                                   <option value="15"> 15 </option>
                                   <option value="16"> 16 </option>
                                   <option value="17"> 17 </option>
                                   <option value="18"> 18 </option>
                                   <option value="19"> 19 </option>
                                   <option value="20"> 20 </option>
                                   <option value="21"> 21 </option>
                                   <option value="22"> 22 </option>
                                   <option value="23"> 23 </option>
                                   <option value="24"> 24 </option>
                                   <option value="25"> 25 </option>
                                   <option value="26"> 26 </option>
                                   <option value="27"> 27 </option>
                                   <option value="28"> 28 </option>
                                   <option value="29"> 29 </option>
                                   <option value="30"> 30 </option>
                                   <option value="31"> 31 </option>               
                               </select>
                               <select name="month" id="month" tabindex="12">
                                   <option value="" selected="selected"> </option>
                                   <option value="January"> January </option>
                                   <option value="February"> February </option>
                                   <option value="March"> March </option>
                                   <option value="April"> April </option>
                                   <option value="May"> May </option>
                                   <option value="June"> June </option>
                                   <option value="July"> July </option>
                                   <option value="August"> August </option>
                                   <option value="September"> September </option>
                                   <option value="October"> October </option>
                                   <option value="November"> November </option>
                                   <option value="December"> December </option>
                               </select>
                               <select name="year" id="year" tabindex="13">
                                   <option value="" selected="selected"> </option>
                                   <option value="1990"> 1990 </option>
                                   <option value="1991"> 1991 </option>
                               </select>
                            </td>
                        </tr>
                        <tr>
                            <td height="46" align="right"> 
                                <label class="loginLabel" id="userGender"> Gender </label>
                            </td>
                            <td align="left">
                                <select name="gender" id="gender" tabindex="14">
                                   <option value="" selected="selected"> </option>
                                   <option value="Male"> Male </option>
                                   <option value="Female"> Female </option>
                                </select>
                            </td>
                        </tr>
                     </table>
    
                     <div id="mustCheck"> </div>
                     <div align="center">
                     	  <label class="loginLabel" style="margin-top:1em; margin-bottom:1em;" id="tAndC"> 
                          <br />
                          I Agree To <a href="#">Terms And Conditions</a> Of Use 
                          </label>

                          <input type="checkbox" name="tacBox" id="tacBox" value="isChecked" tabindex="15">
                          <br />
                          <br />
                          <input name="signUp" type="submit" value="Sign Up" />
                      </div>

                  </td>
	      </tr>
         </table>
				
     </form>

Mark thread solved !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.