Welcome to Dream.In.Code
Getting Help is Easy!

Join 118,309 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,687 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Sign Up Form (Form Validation not working)

 
Reply to this topicStart new topic

Sign Up Form (Form Validation not working), Form Validation not working

liverpool0912
post 31 Jul, 2008 - 04:27 AM
Post #1


New D.I.C Head

*
Joined: 4 Jun, 2008
Posts: 36


My Contributions


Hi im pretty new in this and so im not sure hwere my code is wrong but im sure its at the form validation part because i can just simply submit it without filling up anything nid hlp thx.

CODE

<?xml version="1.0" encoding="iso-8859-1"?>
<!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>
<title>Form Validation</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<script src="validation.js></script>
<script language="JavaScript" type="text/javascript">
function isEmpty(strng) {
    var error = "";
  if (strng.length == 0) {
     error = "The mandatory text area has not been filled in.\n"
     }
     return error;      
}

function checkEmail (strng) {
    var error="";
    if (isEmpty(strng)) {
         error = "You didn't enter an email address.\n";
    }

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) {
    error = "Please enter a valid email address.\n";
    } else {
        var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
        if (strng.match(illegalChars)) {
            error = "The email address contains illegal characters.\n";
        }
    }
    return error;    
}


function checkPhone (strng) {
    var error = "";
    if (isEmpty(strng)) {
        error = "You didn't enter a phone number.\n";
    }
    
    var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
    if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.";
    }
    if (!(stripped.length == 8)) {
        error = "The phone number is the wrong length. Make sure you included an area code.\n";
    }
    return error;
}


function checkPassword (strng) {
    var error = "";
    if (isEmpty(strng)) {
        error = "You didn't enter a password.\n";
    }
    
    var illegalChars = /[\W]/;
    if ((strng.length < 6) || (strng.length > 8)) {
        error = "The password is the wrong length.\n";
    }    else if (illegalChars.test(strng)) {
        error = "The password contains illegal characters.\n";
    } else if ((!strng.match(/[a-z]+/)) || (!strng.match(/[A-Z]+/)) || (!strng.match(/[0-9]+/))) {
        error = "The password must contain at least one uppercase letter, one lowercase letter, and one numeral.\n";
    }
    return error;    
}    


function verifyPass (strng) {
    var error = "";
    if(isEmpty(strng)) {
        error = "You didn't enter a password.\n";
    }
    if(password != veripass) {
        error= "The password you keyed does not match the previous one.Try again. \n";
    }
    return error;
}

function checkUsername (strng) {
    var error = "";
    if (isEmpty(strng)) {
         error = "You didn't enter a username.\n";
    }

    var illegalChars = /\W/;
    if ((strng.length < 4) || (strng.length > 10)) {
         error = "The username is the wrong length.\n";
    } else if (illegalChars.test(strng)) {
        error = "The username contains illegal characters.\n";
    }
    return error;
}
  
function checkName (strng) {
    var error = "";
    if (isEmpty(strng)) {
         error = "You didn't enter your name.\n";
    }

    var illegalChars = /\W/;
        if (illegalChars.test(strng)) {
        error = "The username contains illegal characters.\n";
    }
    return error;
}  
    
function checkAge (strng) {
    var error="";
    if (isEmpty(strng)) {
         error = "You didn't enter your age.\n";
    }
    var illegalChars = /\W/;
        if (illegalChars.test(strng)) {
        error = "The age contains illegal characters.\n";
    }
    return error;
}

function checkCredit (strng) {
    var error = "";
    if (isEmpty(strng)) {
        error = "You didn't enter your card numbern";
    }
    
    var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
    if (isNaN(parseInt(stripped))) {
        error = "The card number contains illegal characters.";
    }
    if (!(stripped.length == 20)) {
        error = "The card number is the wrong length. Make sure you type in correctly.\n";
    }
    return error;
}  

function checkAddress (strng) {
    var error="";
    if (isEmpty(strng)) {
         error = "You didn't enter an address.\n";
    }
        var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
        if (strng.match(illegalChars)) {
            error = "The address contains illegal characters.\n";
        }
    return error;    
}

function checkRadioCheck(theRadioCheck, theType) {
    var error = "";
    for (i=0, n=theRadioCheck.length; i<n; i++) {
        if (theRadioCheck[i].checked) {
            var checkvalue = theRadioCheck[i].value;
            break;
        }
    }
    if (!(checkvalue)) {
        error = "Please check a "+theType+" button.\n";
    }
    return error;
}


function checkDropdown(choice) {
    var error = "";
    if (choice == 0) {
        error = "You didn't choose an option from the drop-down list.\n";
    }    
    return error;
}    

function checkFormvalidation(theForm) {
    var why = "";
    why += checkEmail(theForm.email.value);
    why += checkPhone(theForm.phone.value);
    why += checkPassword(theForm.password.value);
    why += verifyPass(theForm.veripass.value);
    why += checkUsername(theForm.username.value);
    why += checkName(theForm.name.value);
    why += checkAge(theForm.age.value);
    why += checkCredit(theForm.number.value);
    why += checkAddress(theForm.address.value);
    why += isEmpty(theForm.notempty.value);
    why += checkRadioCheck(theForm.radios, "radio");
    why += checkRadioCheck(theForm.checks, "checkbox");
    why += checkDropdown(theForm.choose.selectedIndex);
    if (why != "") {
       alert(why);
       return false;
    }
return true;
}
</script>

<body>
<form action="file:///F:/Web%20D/WEB%20D/Main.html" name="Particular" id="Particular" method="post" onSubmit="return checkInputForm(this)">

<h1>User Information</h1>
Username: <input name="username" type="text" /><br />
Password: <input name="password" type="text" /><br />
Verify Password: <input name="veripass" type="text" /><br />
<br />

<h2>User Personal Information</h2>
User Full name: <input name="name" type="text" /><br />
Email: <input name="email" type="text" /><br />
Gender: <input name="radios" type="radio" value="Female">Female<input name="radios" type="radio" value="Male">Male<br />
Title: <select name="choose">
    <option>Miss</option>
    <option>Mrs</option>
    <option>Mdm</option>
    <option selected="selected">Mr</option>
</select><br />
Where did you hear about this website: <input type="checkbox" />Friends<input type="checkbox" />Other sites' links<input type="checkbox" />Just happen to stumble in<br />
<br />

<h3>Other Information</h3>
Mailing Address: <input name="address" type="text" /><br />
Credit Card Number: <input name="number" type="text" /><br />
Age: <input name="age" type="text" /><br />
Occupation: <select name="choose">
        <option>Student</option>
        <option>Manager</option>
        <option>Teacher</option>
        <option>Engineer</option>
        <option>salesperson</option>
            <option selected="selected">Others</option>
</select><br />
<br />

Which console do you prefer: <input name="radios" type="radio" value="XBOX">XBOX<input name="radios" type="radio" value="PS series">PS series<input name="radios" type="radio" value="Nintendo">Nintendo<input name="radios" type="radio" value="Wii">Wii<br />
Special Interest:<select name="choose">
        <option>DOTA</option>
        <option>Gears Of War</option>
        <option>Final Fantasy Series</option>
        <option>Maplestory</option>
        <option>Audition</option>
            <option>Soul Calibur</option>
        <option>Dead Or Alive</option>
        <option>Call Of Duty</option>
        <option>Gunbound</option>
        <option>Warrock</option>
            <option selected="selected">Others</option>
</select><br />



<input type="reset" /><br />
<input type="submit" /><br />

</form>
</body>
</html>
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/10/08 11:41AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month