/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Javascript only validating one field at a time in a multi field form!

my javascript code is only validating one field at a time (as in it validates on field then submits the form, instead of going through the entire thing and then returning it as true and submitting it…)

I’m not sure what to do to be honest, I’ve looked up google to no real avail..

my variables are declared in a seperate file to the actual even handlers and I have heaps of comments through out it, so please don’t judge lol i’m still learning ?

[QUOTE]

//Event Registrations (Variable Declarations) found in validation_chkr.js

//Validate Entire Form using validate_join()
function validate_join()
{

//Validate Mobile Phone Numer Entered
if (posmobile != 0) {
alert (“The phone number (” + llphone.value +
“)is not in the correct format n” +
“Please re-enter your mobile number”);
mphone.focus();
mphone.select();
return false;
}

//Validate Occupation Selected
if(occupation.selectedIndex==0)
{
alert(“Please select an Occupation from the List”);
occupation.focus();
occupation.select();
return false;
}

//Validate Landline Phone Numer Entered
if (poslandline != 0) {
alert (“The phone number (” + llphone.value +
“)is not in the correct format n” +
“Please re-enter your landline number”);
llphone.focus();
llphone.select();
return false;
}

//Validate Email Field
if (pos != 0) {
alert(“The email supplied(” + email.value +
“) is not a valid email address. n” +
“Please re-enter your email address”);
email.focus();
email.select();
return false;
}

//Validate Surname Field
if(surname.value == “”){
alert(“Please enter surname”);
surname.focus();
return false;
}

//Validate Othername Field
if(othername.value == “”){
alert(“Please enter othername”);
othername.focus();
return false;
}

// Validate Address Field (if address 1 has nothing in it or address 2 has nothing in it then alert user
if(address1.value == “” && address2.value == “”){
alert(“Please enter Delivery Address”);
address1.focus();
return false;
}

//Validate Username Field
if(username.value == “”){
alert(“Please enter username”);
username.focus();
return false;
}

//Check if White Space Appears in Username Field
else if(!re.test(username.value)) {
alert(“Error: Username must contain only letters, numbers and underscores!”);
username.focus();
return false;
}

//Check Length of Username Field (between 6 and 10 characters)
else if((username.value).length < 6 || (username.value).length >10){
alert(“username must composed of 6-10 digits”);
username.focus();
return false;
}

//Validate Password Field
if(password1.value != “” && password1.value == password2.value) {
if(password1.value.length < 6) {
alert(“Error: Password must contain at least six characters!”);
password1.focus();
return false;
}

//Check Username is Different to Password
if(password1.value == username.value) {
alert(“Error: Password must be different from Username!”);
password1.focus();
return false;
}

//Check Password contains a Minimum of one Number
if(!re2.test(password1.value)) {
alert(“Error: password must contain at least one number (0-9)!”);
password1.focus();
return false;
}

//Check Password contains one Lower Case Letter
if(!re3.test(password1.value)) {
alert(“Error: password must contain at least one lowercase letter (a-z)!”);
password1.focus();
return false;
}

//Check Password contains on Upper Case Letter
if(!re4.test(password1.value)) {
alert(“Error: password must contain at least one uppercase letter (A-Z)!”);
password1.focus();
return false;
}
}

//Validate Postcode Field (if nothing present alert user)
if(postcode.value == “”){
alert(“Please enter postcode”);
postcode.focus();
return false;
}

//Validate Postcode Field (if something other than a number is entered then alert user)
else if(IsNumeric(postcode.value) == false){
alert(“Please enter postcode (Numbers only)”);
postcode.focus();
return false;
}

return true;

}

[/QUOTE]

Variables:

[QUOTE]

//validation_chkr.js
//Event Registrations for validation_chk.js

//Surname Variable Registered
var surname = document.getElementById(“surname”)

//Othername Variable Registered
var othername = document.getElementById(“othername”)

//Address Line 1 Variable Registered
var address1 = document.getElementById(“address1”)

//Address Line 2 Variable Registered
var address2 = document.getElementById(“address2”)

//Postcode Variable Registered
var postcode = document.getElementById(“postcode”)

//Username Variable Registered
var username = document.getElementById(“username”)

// Password and User Name Restrictions Registered – The reason I did not use multiple/ ‘look ahead’ regular expressions is due to older browswers
// Not being supported, therefore possibly not recognising the appropriate regular experessions
var re = /^w+$/
var re2 = /[0-9]/
var re3 = /[a-z]/
var re4 = /[A-Z]/

//Password 1(Initial) Variable Registered
var password1 = document.getElementById(“initial”)

//Password 2(Second) Variable Registered
var password2 = document.getElementById(“second”)

//Occupation Variable Registered
var occupation = document.getElementById(“occupation”)

//Contact Method Variable Registered
var radios = document.getElementsByName(“contactmethod”)

//Email Variable Registered
var email = document.getElementById(“email”)
//Email Restrictions Registered
var pos = email.value.search(/^.+@.+..{2,3}$/)
//Emailreturn Variable Registered (used to compare with pos for pattern matching)
var emailreturn = 0;

//Landline Variable Registered
var llphone = document.getElementById(“landline”);
//Landline Restrictions Registered
var poslandline = llphone.value.search(/^d{2}-d{3}-d{3}$/)

//Landline Variable Registered
var mphone = document.getElementById(“mobile”);
//Landline Filter REgistered
var posmobile = mphone.value.search(/^d{2}-d{4}-d{4}$/)

[/QUOTE]

if someone could help (without changing my coding too much if possible) i’d be very appreciative ?

THANKS

to post a comment
JavaScript

37 Comments(s)

Copy linkTweet thisAlerts:
@FangAug 17.2010 — Do you have this&lt;form [COLOR="Blue"]onsubmit="return function validate_join();"[/COLOR] action="" method="post" name="form1"&gt;

Are there any errors in the console?
Copy linkTweet thisAlerts:
@web_dev_is_hardauthorAug 17.2010 — hi Fang, thanks for the quick reply!

yes i do have the call to function in the form tag, and no there are no errors in the error console (using Fire Fox)... by the looks of my code, should it be working, i.e. have i done it right to your expert eyes ?
Copy linkTweet thisAlerts:
@FangAug 17.2010 — Need to see the html
Copy linkTweet thisAlerts:
@web_dev_is_hardauthorAug 17.2010 — Hope its not too hard to read ? seriously can't thank you enough for helping me ?


<?xml version="1.0" encoding="UTF-8"?>

<!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 name="description" content="JavaScript XHTML CSS ASP.NET"/>

<meta name="keywords" content="HTML, CSS, JavaScript, ASP.NET"/>

<link rel="stylesheet" type="text/css" href="index.css" />

<script type="text/javascript" src="validation_chk.js"></script>

<!-- Puts the date in the Join Date text box so once the form is submitted it displays the time -->

<script type="text/javascript">

window.onload = function(){

var joindate = document.getElementById("joindate")

joindate.value = new Date().toLocaleString();

}

</script>

<title> FUNK IT Solutions </title>

</head>

<body>

<div id="supercontainer">

<div id="splat3"> <img src="images/Splat3.png" alt="yellow splat"/></div>

<div id="splat4"> <img src="images/Splat4.png" alt="green splat"/></div>

<div id="wrapper">

<div id="container">

<div id="header">

<h1>FUNK IT <br/> <span id="caption">"Your IT Solution Specialist"</span></h1>

<b>Phone Us TODAY:</b> 0422 146 295

</div>

<div id="menu">
<span class="menuitem" >&nbsp; <a href="index.html">Home</a> &nbsp; </span>|
<span class="menuitem" >&nbsp;<a href="aboutus.html">ASP.NET Example</a> &nbsp; </span>|
<span class="menuitem">&nbsp; <a href="join.html">Join Us</a> &nbsp; </span>|
<span class="menuitem">&nbsp; <a href="techzone.html">TechZone</a> &nbsp; </span>|
<span class="menuitem">&nbsp; <a href="auction.html">Auction</a> &nbsp; </span>|
<span class="menuitem">&nbsp; <a href="contact.html">Contact Us</a> &nbsp; </span>|
</div>

<div id="middlecontent" style="filter:alpha(opacity=80); opacity:0.8;">
<br />
<h2 class="middletext">Register</h2>
<h5 class="middletext"> Registering allows users to have access to auctions as well as other exclusive parts of the site
best of all its free.</h5>


<form action="" onsubmit="return validate_join()" method="post" >
<table class="middletext" border="0" width = "100%">
<tr>
<td width="50%" ><b>Surname:</b> <br /> <input type="text" id="surname" maxlength="30" /></td>
<td width="50%"><b>Other Names:</b> <br /> <input type="text" name= "othername" id="othername" maxlength="60" /> </td>
</tr>
<tr>
<td width="50%"><b>E-mail:</b> <br /> <input type="text" id="email" maxlength="30" /></td>
<td width="50%"><br /> <br /><b>Prefered Contact Method</b><br />
<input type="radio" name="contactmethod" value="email" checked="checked" /> E-Mail<br />
<input type="radio" name="contactmethod" value="mobile" /> Mobile<br />
<input type="radio" name="contactmethod" value="landline" /> Day Time Telephone<br />
</td>
</tr>
<tr>
<td width="50%">
<b>Delivery Address:</b> <br />
<input type="text" name="address1" id="address1" value="" size="25" /> <br />
<input type="text" name="address2" id="address2" value="" size="25" /> <br />
<input type="text" name="postcode" id="postcode" value="" size="10" />
</td>
<td width="50%">
<b>Day Time Telephone:</b> <br /> <input type="text" id="landline" value="" size="25" />
<br />
<b>Mobile:</b> <br /> <input type="text" id="mobile" name="mobilenumber" value="" size="25" />
</td>
</tr>
<tr>
<td width="50%">
<br /> <br /><b>Occupation:</b> <br />
<select id="occupation">
<option value="" selected="selected">-- SELECT --</option>
<option value ="1"> Un-Employed </option>
<option value ="2"> Student </option>
<option value ="3"> Engineer </option>
<option value ="4"> Self-Employed </option>
<option value ="5"> Teacher</option>
<option value ="6"> Health Professiona;</option>
<option value ="7"> Accountant</option>
<option value ="8"> IT Professional</option>
<option value ="9"> Hospitality Professional</option>
<option value ="0"> Law Professional</option>
</select>
</td>
<td style="visibility:hidden" width="50%"> <br /> <br /><b>Join Date:</b> <br />
<input type="text" name="joindate" id="joindate" size="25" />
</td>
</tr>
<tr>
<td width="50%">
<br /> <br /> <br /> <br /><b>User Name:</b> <br /> <input type="text" name="username" id="username" value="" maxlength="12" />
<br />
<b>Password:</b> <br /> <input type="password" id="initial" maxlength="10" /> <br />
<b>Confirm Password:</b> <br /> <input type="password" id="second" maxlength="10" />
</td>
</tr>
</table>
<br />
<br />
<div id="buttons"> <input type="submit" name="submit" id="submit" value="Submit"/> <input type="reset" name="reset" id="reset"/></div>
</form>
</div>

<!-- Script for registering the event handlers/ variables -->
<script type="text/javascript" src="validation_chkr.js"> </script>

<div class="lefttext" id="leftcolumn" style="filter:alpha(opacity=80); opacity:0.8;">
<span style="font-size:16px; font-weight:bold;"> DO YOU NEED IT TRAINING?</span>
<hr />
<span class="lefttext" >We Offer Training In:</span>
<ul style="text-align: left">
<li>Microsoft Office</li>
<li>Adobe</li>
<li>Windows</li>
<li>Apple Mac</li>
<li>Web Design</li>
<li>Web Development</li>
<li>AND MORE</li>
</ul>
<hr />
<img src="images/webdev2logo.png" alt="Advertisment" width="200" height="200"/>
<hr />
<span class="lefttext"> We Promise You:</span>
<ul style="text-align: left">
<li>Friendly Staff</li>
<li>Professional Service</li>
<li>Easy to Understand</li>
<li>Qualified Teachers</li>
<li>Distance Education</li>
<li>Courses Taylored to Suit Your Needs!</li>
</ul>
<hr />
<p>
<a href="http://jigsaw.w3.org/css-validator/check/referer">
<img style="border:0;width:88px;height:31px"
src="http://jigsaw.w3.org/css-validator/images/vcss-blue"
alt="Valid CSS!" /> </a>

<a href="http://validator.w3.org/check?uri=referer">
<img style="border:0" src="http://www.w3.org/Icons/valid-xhtml10"
alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a>
</p>

</div>
</div>
<div id="splat2"> <img src="images/Splat2.png" alt="purple splat"/></div>
<div id="splat1"> <img src="images/Splat1.png" alt="blue splat"/></div>
<div class="footer">
<p>Copywrite &copy; 2010</p>
</div>
</div>

</div>

</body>

</html>[/QUOTE]
Copy linkTweet thisAlerts:
@annaunivrajanAug 17.2010 — Call the function in the onsubmit even of your page. The return type of the function will determine whether the page has to submit or not. So keep the synax as below.


onsubmit="return function validate_join();"
Copy linkTweet thisAlerts:
@web_dev_is_hardauthorAug 17.2010 — i did try it with the onsubmit="return function validate_join();" syntax but it just plain ignored the javascript file...

do you think it will help if i put the on submit in the submit button area? <-- don't worry just tried this it didn't work :s
Copy linkTweet thisAlerts:
@FangAug 17.2010 — Place the variables in the function validate_join()
Copy linkTweet thisAlerts:
@annaunivrajanAug 17.2010 — Have you included the "validation_chkr.js " file in your current file using external javascript file inclusion?

Or better include all the varibales in your original file itself. Do not make it two different files.
Copy linkTweet thisAlerts:
@web_dev_is_hardauthorAug 17.2010 — i just tried it still won't do anything... see a certain part of the JavaScript code, will flow, but its things like phone numbers, email etc that are continuing to try to validate with out moving on to the next field...
Copy linkTweet thisAlerts:
@FangAug 17.2010 — The variables must be placed in the function as, in some cases, a regex is used to provide a result.
Copy linkTweet thisAlerts:
@annaunivrajanAug 17.2010 — Hi,

Make seperate function for each validation.

According to your code, you are checking all the fields everytime. Your code style is like, if i press a "Validate" button it should check all the fields and then submit,if all are valid.

To control this, you need to write seperate functions like validateEmail(), validatePhone() etc.. and call then and there you need.


Please do not make a seperate file for variable declaration. By default, all the variables are global in nature in javascript. So make the variable before the function call.

Regards,

P. Rajan
Copy linkTweet thisAlerts:
@web_dev_is_hardauthorAug 17.2010 — i'll give that a go and let you know how I do...

that means i would have to declare them like

document.getElementById ("surname") = chkSurname

and then in the function i could have it as

Function {

...blah blah blah...

chkSurname () {

if statement...

}

...rest of code blah blah blah...

}

???

Will try it and let you know how I go ?
Copy linkTweet thisAlerts:
@web_dev_is_hardauthorAug 17.2010 — sorry double post... but I tried it with 2 fields i put in


// Declarations and Call to Functions...

document.getElementByID ("mobile") = chkMobile

document.getElementByID ("Occupation") = chkOccupation[/QUOTE]


^ the FF error console is saying that document.getElementByID is not a function... ??

the for the function i used...


//Validate Entire Form using validate_join()

function validate_join()

{

//Validate Mobile Phone Numer Entered

chkMobile () {

if (posmobile != 0) {

alert ("The phone number (" + mphone.value +

")is not in the correct format (e.g 04-2214-6295) n" +

"You MUST inculde the [-] character n" +

"Please re-enter your mobile number");

mphone.focus();

mphone.select();

return false;

}


//Validate Occupation Selected

chkOccupation () {

if(occupation.selectedIndex==0)

{

alert("Please select an Occupation from the List");

occupation.focus();

occupation.select();

return false;

} [/QUOTE]


do I actually have to do anything else? im a bit confused now... does anyone have msn or yahoo or are they not allowed here? (just asking cause im not too sure ? )

Thanks

Phil
Copy linkTweet thisAlerts:
@FangAug 17.2010 — Your original code works correctly when the variables are included in the function validate_join()
Copy linkTweet thisAlerts:
@web_dev_is_hardauthorAug 17.2010 — so you actually got it to work!!!! the ENTIRE THING!!???

so what do I have to do? just move the variables to be declared before the function form?
Copy linkTweet thisAlerts:
@FangAug 17.2010 — In the function. //Validate Entire Form using validate_join()
function validate_join()
{
//Surname Variable Registered
var surname = document.getElementById("surname")

//Othername Variable Registered
var othername = document.getElementById("othername")

//Address Line 1 Variable Registered
var address1 = document.getElementById("address1")

//Address Line 2 Variable Registered
var address2 = document.getElementById("address2")

//Postcode Variable Registered
var postcode = document.getElementById("postcode")

//Username Variable Registered
var username = document.getElementById("username")

// Password and User Name Restrictions Registered - The reason I did not use multiple/ 'look ahead' regular expressions is due to older browswers
// Not being supported, therefore possibly not recognising the appropriate regular experessions
var re = /^w+$/
var re2 = /[0-9]/
var re3 = /[a-z]/
var re4 = /[A-Z]/

//Password 1(Initial) Variable Registered
var password1 = document.getElementById("initial")

//Password 2(Second) Variable Registered
var password2 = document.getElementById("second")

//Occupation Variable Registered
var occupation = document.getElementById("occupation")

//Contact Method Variable Registered
var radios = document.getElementsByName("contactmethod")

//Email Variable Registered
var email = document.getElementById("email")
//Email Restrictions Registered
var pos = email.value.search(/^.+@.+..{2,3}$/)
//Emailreturn Variable Registered (used to compare with pos for pattern matching)
var emailreturn = 0;

//Landline Variable Registered
var llphone = document.getElementById("landline");
//Landline Restrictions Registered
var poslandline = llphone.value.search(/^d{2}-d{3}-d{3}$/)

//Landline Variable Registered
var mphone = document.getElementById("mobile");
//Landline Filter REgistered
var posmobile = mphone.value.search(/^d{2}-d{4}-d{4}$/)
//Validate Mobile Phone Numer Entered
if (posmobile != 0) {
alert ("The phone number (" + llphone.value +
")is not in the correct format n" +
"Please re-enter your mobile number");
mphone.focus();
mphone.select();
return false;
}

//Validate Occupation Selected
if(occupation.selectedIndex==0)
{
alert("Please select an Occupation from the List");
occupation.focus();
occupation.select();
return false;
}

//Validate Landline Phone Numer Entered
if (poslandline != 0) {
alert ("The phone number (" + llphone.value +
")is not in the correct format n" +
"Please re-enter your landline number");
llphone.focus();
llphone.select();
return false;
}

//Validate Email Field
if (pos != 0) {
alert("The email supplied(" + email.value +
") is not a valid email address. n" +
"Please re-enter your email address");
email.focus();
email.select();
return false;
}

//Validate Surname Field
if(surname.value == ""){
alert("Please enter surname");
surname.focus();
return false;
}

//Validate Othername Field
if(othername.value == ""){
alert("Please enter othername");
othername.focus();
return false;
}

// Validate Address Field (if address 1 has nothing in it or address 2 has nothing in it then alert user
if(address1.value == "" &amp;&amp; address2.value == ""){
alert("Please enter Delivery Address");
address1.focus();
return false;
}

//Validate Username Field
if(username.value == ""){
alert("Please enter username");
username.focus();
return false;
}

//Check if White Space Appears in Username Field
else if(!re.test(username.value)) {
alert("Error: Username must contain only letters, numbers and underscores!");
username.focus();
return false;
}

//Check Length of Username Field (between 6 and 10 characters)
else if((username.value).length &lt; 6 || (username.value).length &gt;10){
alert("username must composed of 6-10 digits");
username.focus();
return false;
}

//Validate Password Field
if(password1.value != "" &amp;&amp; password1.value == password2.value) {
if(password1.value.length &lt; 6) {
alert("Error: Password must contain at least six characters!");
password1.focus();
return false;
}

//Check Username is Different to Password
if(password1.value == username.value) {
alert("Error: Password must be different from Username!");
password1.focus();
return false;
}

//Check Password contains a Minimum of one Number
if(!re2.test(password1.value)) {
alert("Error: password must contain at least one number (0-9)!");
password1.focus();
return false;
}

//Check Password contains one Lower Case Letter
if(!re3.test(password1.value)) {
alert("Error: password must contain at least one lowercase letter (a-z)!");
password1.focus();
return false;
}

//Check Password contains on Upper Case Letter
if(!re4.test(password1.value)) {
alert("Error: password must contain at least one uppercase letter (A-Z)!");
password1.focus();
return false;
}
}

//Validate Postcode Field (if nothing present alert user)
if(postcode.value == ""){
alert("Please enter postcode");
postcode.focus();
return false;
}

//Validate Postcode Field (if something other than a number is entered then alert user)
else if(IsNumeric(postcode.value) == false){
alert("Please enter postcode (Numbers only)");
postcode.focus();
return false;
}

return true;
}
Copy linkTweet thisAlerts:
@web_dev_is_hardauthorAug 17.2010 — OK!! thanks... lol this is probably getting annoying for you more than me! but im just happy i have found somewhere to come to get help!

i copied the code u gave me Fang, and it does submit after entering the proper phone number, but then it asks to select an occupation and before you get the chnance to select the occupation the form returns true and submits...

btw im having it go to an echo form, but that shouldn't make any difference i don't think ?
Copy linkTweet thisAlerts:
@FangAug 17.2010 — Remove [COLOR="Green"]occupation.select();[/COLOR]
Copy linkTweet thisAlerts:
@web_dev_is_hardauthorAug 17.2010 — U are a genius!!!!

just one more little problem :p the password field is not being validated now... any ideas ?
Copy linkTweet thisAlerts:
@FangAug 17.2010 — if(password1.value != "" &amp;&amp; (password1.value != password2.value)) {
Copy linkTweet thisAlerts:
@web_dev_is_hardauthorAug 17.2010 — didn't do anything :S still just entierly misses the password field

....?
Copy linkTweet thisAlerts:
@FangAug 17.2010 — //Validate Entire Form using validate_join()
function validate_join()
{
//Surname Variable Registered
var surname = document.getElementById("surname")

//Othername Variable Registered
var othername = document.getElementById("othername")

//Address Line 1 Variable Registered
var address1 = document.getElementById("address1")

//Address Line 2 Variable Registered
var address2 = document.getElementById("address2")

//Postcode Variable Registered
var postcode = document.getElementById("postcode")

//Username Variable Registered
var username = document.getElementById("username")

// Password and User Name Restrictions Registered - The reason I did not use multiple/ 'look ahead' regular expressions is due to older browswers
// Not being supported, therefore possibly not recognising the appropriate regular experessions
var re = /^w+$/
var re2 = /[0-9]/
var re3 = /[a-z]/
var re4 = /[A-Z]/


//Occupation Variable Registered
var occupation = document.getElementById("occupation")

//Contact Method Variable Registered
var radios = document.getElementsByName("contactmethod")

//Email Variable Registered
var email = document.getElementById("email")
//Email Restrictions Registered
var pos = email.value.search(/^.+@.+..{2,3}$/)
//Emailreturn Variable Registered (used to compare with pos for pattern matching)
var emailreturn = 0;

//Landline Variable Registered
var llphone = document.getElementById("landline");
//Landline Restrictions Registered
var poslandline = llphone.value.search(/^d{2}-d{3}-d{3}$/)

//Landline Variable Registered
var mphone = document.getElementById("mobile");
//Landline Filter REgistered
var posmobile = mphone.value.search(/^d{2}-d{4}-d{4}$/)


//Password 1(Initial) Variable Registered
var password1 = document.getElementById("initial")

//Password 2(Second) Variable Registered
var password2 = document.getElementById("second")

//Validate Password Field
if(password1.value != "" &amp;&amp; (password1.value != password2.value)) {
if(password1.value.length &lt; 6) {
alert("Error: Password must contain at least six characters!");
password1.focus();
return false;
}

//Check Username is Different to Password
if(password1.value == username.value) {
alert("Error: Password must be different from Username!");
password1.focus();
return false;
}

//Check Password contains a Minimum of one Number
if(!re2.test(password1.value)) {
alert("Error: password must contain at least one number (0-9)!");
password1.focus();
return false;
}

//Check Password contains one Lower Case Letter
if(!re3.test(password1.value)) {
alert("Error: password must contain at least one lowercase letter (a-z)!");
password1.focus();
return false;
}

//Check Password contains on Upper Case Letter
if(!re4.test(password1.value)) {
alert("Error: password must contain at least one uppercase letter (A-Z)!");
password1.focus();
return false;
}
}


//Validate Mobile Phone Numer Entered
if (posmobile != 0) {
alert ("The phone number (" + llphone.value +
")is not in the correct format n" +
"Please re-enter your mobile number");
mphone.focus();
mphone.select();
return false;
}

//Validate Occupation Selected
if(occupation.selectedIndex==0)
{
alert("Please select an Occupation from the List");
occupation.focus();
//occupation.select();
return false;
}

//Validate Landline Phone Numer Entered
if (poslandline != 0) {
alert ("The phone number (" + llphone.value +
")is not in the correct format n" +
"Please re-enter your landline number");
llphone.focus();
llphone.select();
return false;
}

//Validate Email Field
if (pos != 0) {
alert("The email supplied(" + email.value +
") is not a valid email address. n" +
"Please re-enter your email address");
email.focus();
email.select();
return false;
}

//Validate Surname Field
if(surname.value == ""){
alert("Please enter surname");
surname.focus();
return false;
}

//Validate Othername Field
if(othername.value == ""){
alert("Please enter othername");
othername.focus();
return false;
}

// Validate Address Field (if address 1 has nothing in it or address 2 has nothing in it then alert user
if(address1.value == "" &amp;&amp; address2.value == ""){
alert("Please enter Delivery Address");
address1.focus();
return false;
}

//Validate Username Field
if(username.value == ""){
alert("Please enter username");
username.focus();
return false;
}

//Check if White Space Appears in Username Field
else if(!re.test(username.value)) {
alert("Error: Username must contain only letters, numbers and underscores!");
username.focus();
return false;
}

//Check Length of Username Field (between 6 and 10 characters)
else if((username.value).length &lt; 6 || (username.value).length &gt;10){
alert("username must composed of 6-10 digits");
username.focus();
return false;
}


//Validate Postcode Field (if nothing present alert user)
if(postcode.value == ""){
alert("Please enter postcode");
postcode.focus();
return false;
}

//Validate Postcode Field (if something other than a number is entered then alert user)
else if(IsNumeric(postcode.value) == false){
alert("Please enter postcode (Numbers only)");
postcode.focus();
return false;
}

return true;
}
Copy linkTweet thisAlerts:
@web_dev_is_hardauthorAug 17.2010 — gahhhhhhhhhhhhhhhh! its still not validating the password ? any other suggestions?

sorry if im being a pain!
Copy linkTweet thisAlerts:
@annaunivrajanAug 17.2010 — Hi,

Can you please give the complete code.. I mean along with the html .?
Copy linkTweet thisAlerts:
@web_dev_is_hardauthorAug 17.2010 — Hi annaunivrajan i did give the code, on page one ? for all files including HTML.
Copy linkTweet thisAlerts:
@FangAug 17.2010 — Added a check for both paswords//Validate Password Field
if(password1.value != "" &amp;&amp; (password1.value != password2.value)) {
if(password1.value.length &lt; 6) {
alert("Error: Password must contain at least six characters!");
password1.focus();
return false;
}

//Check Username is Different to Password
if(password1.value == username.value) {
alert("Error: Password must be different from Username!");
password1.focus();
return false;
}

//Check Password contains a Minimum of one Number
if(!re2.test(password1.value)) {
alert("Error: password must contain at least one number (0-9)!");
password1.focus();
return false;
}

//Check Password contains one Lower Case Letter
if(!re3.test(password1.value)) {
alert("Error: password must contain at least one lowercase letter (a-z)!");
password1.focus();
return false;
}

//Check Password contains on Upper Case Letter
if(!re4.test(password1.value)) {
alert("Error: password must contain at least one uppercase letter (A-Z)!");
password1.focus();
return false;
}

//Check Password1 &amp; Password2
if(password1.value != password2.value) {
alert("Error: Password must be the same as Confirm Password!");
password2.focus();
return false;
}
}
Copy linkTweet thisAlerts:
@web_dev_is_hardauthorAug 17.2010 — IT STILL WON'T VALIDATE! im trying everything you are telling me plus more! its weird cause they validate when i test them on there own but as part of this function they just don't want to execute
Copy linkTweet thisAlerts:
@FangAug 17.2010 — Full document attached

[upl-file uuid=00ab8344-f4b2-443f-b15e-ae53e34c4493 size=3kB]wd.zip[/upl-file]
Copy linkTweet thisAlerts:
@web_dev_is_hardauthorAug 17.2010 — can I just ask... are you actually viewing this code in your browser?... can you see my design etc?

cause if you can and it works for you... something weird is going on, it doesn't want to validate for me... everything else is great but the password is still being WEIRD!!!
Copy linkTweet thisAlerts:
@annaunivrajanAug 17.2010 — Is that problem solved?
Copy linkTweet thisAlerts:
@web_dev_is_hardauthorAug 17.2010 — nope ?

my password field won't validate... i have no idea cause im still learning java and i have to have this done by tomorrow...

no joke i have been working on this for soooo long and am only starting to kind of understand javascript a little better... hopefully someone will be able to help me with a solution, THANK YOU SOOO much to u and Fang for trying to help I really am thankful! ?
Copy linkTweet thisAlerts:
@FangAug 17.2010 — It validates in accordance with the regex
Copy linkTweet thisAlerts:
@web_dev_is_hardauthorAug 17.2010 — ... so does that mean it won't work as part of the function?

im so confused ... could you please explain to me why???

Thanks ?
Copy linkTweet thisAlerts:
@FangAug 17.2010 — The zipped document works as expected. In what way does the password field not validate?
Copy linkTweet thisAlerts:
@web_dev_is_hardauthorAug 17.2010 — it completely ignores the password fields... it will go through every other field and check it...

I even used the file you sent me EXACTLY as it was i didn't change ANYTHING and it still skips the password validation

Do you think it could be my computer?

But if it is why do you think it validates the password field when they are placed in there own function and not the validate_join() function??
Copy linkTweet thisAlerts:
@FangAug 17.2010 — This should fix itif(password1.value == "" || (password1.value != password2.value)) {
Copy linkTweet thisAlerts:
@web_dev_is_hardauthorAug 17.2010 — OMGOSH!!!! it WORKS!!!! THANK YOU SO SO SO SO SO MUCH!!! ? I'm so grateful ?

THANK YOU FANG!!!!

p.s. add me on msn if u want (as it says in my signature) i always like talking to web developers since its what I want to get into when I finish studying... either way

THANK YO U?
×

Success!

Help @web_dev_is_hard spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...