JavaScript - Validation Challenge
First of please bear with me i am beginner.
I am trying to validate the form with the code below. What I want is "Only positive whole numbers from 0 to 9 in the username field to be validated". for example 125087 without comas,slashes,floats points etc. I just want positive digits from 0 to 9. can any body help me. I would really appreciate it. Thanks Code: <html> <head> <script type="text/javascript> funtion validateForm() { var x=document.forms["loginForm"]["user"].value if (x==null || x=="") { alert("Username must be filled out"); return false; } } </script> </head> <body> <form action="" name="loginForm" onsubmit="return validateForm()" method="post"> Username:<input type="text" name="user" /> <input type="submit" value="submit" /> </form> </body> </html> Similar TutorialsHi, my friend made a page designed to test me - with no javascript skills at all - and I cant get past his stage 2. Could you guys help? Code: <!-- // try figuring out the password, without just jumping pages // You'll need to look 'Closer' // ~Stewie var password, i; password=prompt("Please enter password!",""); if (password=="window.location == /lvl2/index.php?user=admin&password=lolreally?123!+") { location="grats.html" i=4; } else { alert("Wrong!") location="authfail.php" } //-->[/] This is where I supposedly find the password. here is the actual page. stewie390.info/lvl2/ i take an google suggestions code. view source... i hope that is the best "ajax google suggestions" code created... and try to understand it. someone can help to understand that javascript ? write remarks... formated code file attached + : Link1 New to this stuff. I am using an HV Menu and want to be able to overlap the parent menu over the background image used for the menus. Each menu item has a background image and I would like the menu to open overlapping this image. Not sure how to do this but am pretty sure it is in the menu_com.js file. Thanks for any help.
Hey all. I have a simple validation I need to do. I need to just make sure that a Checkbox is checked, and that a Text field has content. Sounds simple but I cannot find any thing that has a check and a text field. Here what I have. Can I modify this script to do this? A Checkbox MUST be checked and Text field MUST be filled out. This currently does the text field fine, but no Checkbox obviously. How can I add a checkbox validation to this? Thats it. Any help is appreciated. Code: <script type="text/javascript"> var textFields = ["digsig"]; function validateForm( ) { var oops = ""; // must initialize this! var form = document.sig; for ( var t = 0; t < textFields.length; ++t ) { var field = form[textFields[t]]; var value = field.value.replace(/^\s+/,"").replace(/\s+$/,""); // trim the input if ( value.length < 1 ) { oops += "You MUST enter your Digital Signature"; } } if ( oops != "" ) { alert("ERROR:" + oops); return false; } } } </script> Hello all, new here Seems like a very nice place to be apart of. I have my website www.gebcn.com. If you view source you will see all that I have done, but more importantly my problem. I have the JS code at the top there and I am unable to W3C validate my HTML because of the JS. I am using XHTML strict and would like to stay using it. The JS I have at the top is my form validation code. I am able to do any validating that I need with this "snippet" of code, I have shrank it from my library version just to use for this newsletter. Until now W3C validating was not important now for some reason it is and I am faced with this problem. I am not a Javascript guy more of a HTML/CSS guy and I can manipulate JS to suit my needs. <problem> I have tried to make this "snippet" of JS code an external file but receive multiple errors with the JS calling for the FORM NAME as it is not on the same page. The form NAME=NEWSLETTER is another problem, as W3C says I am unable to use attribute "NAME" in this location. <problem> I would like to keep the JS close to how it is now as I have a library to use this JS over and over again. Any pointers in the right direction or solutions to my problem would be greatly appreciated. Thanks! Hopefully it is not to hard huh If there is anything anyone needs, the code pasted here, or anything else please let me know. Thanks again! Hi All, I have a java script invoked within an ANT template. This java script as of now converts a text file to xml file. Now, how would I do the schema validation of that XML file against an XSD in the javascript? Saw many examples online but they were using MSXML or java classes Would be glad to have any sort of suggestions.. Thanks Hi, got my form here Code: <form method="POST" onsubmit="return validateFormOnSubmit1(this)" action="sendEmail.php"> <p class="demo2">Receivers E-mail<a class="textFields"> <input type="text" name="receiver" size="30" maxlength="35" /></a></p> <p class="demo2">Senders E-mail<a class="textFields2"> <input type="text" name="sender" size="30" maxlength="35" /></a></p> <p class="btn" > <input name="Submit" type="submit" value="Send"/></p> </form> And that should call up this Code: function validateFormOnSubmit1(theForm) { var reason = ""; reason += validateEmail1(theForm.receiver); reason += validateEmail1(theForm.sender); if (reason != "") { alert("Some fields need correction:\n" + reason); return false; } return true; } function trim(s) { return s.replace(/^\s+|\s+$/, ''); } function validateEmail1(fld) { var error=""; var tfld = trim(fld.value); // value of field with whitespace trimmed off var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ; var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ; if (fld.value == "") { fld.style.background = 'Yellow'; error = "You didn't enter an email address.\n"; } else if (!emailFilter.test(tfld)) { //test email for illegal characters fld.style.background = 'Yellow'; error = "Please enter a valid email address.\n"; } else if (fld.value.match(illegalChars)) { fld.style.background = 'Yellow'; error = "The email address contains illegal characters.\n"; } else if (fld.value.length == 0) { fld.style.background = 'Yellow'; error = "The required field has not been filled in.\n" } else { fld.style.background = 'White'; } return error; } For some reason though the validation is not working. Is there anything obvious I am doing wrong? cheers Hey. Could someone point me in the direction of why this is not working, it worked in my last program, but not since I have changed things. I have a standard html form Code: <form method="POST" onsubmit="return validate_form(this)" action="anniversaryPreview.php"> <p class="demo5">Senders Name<a class="textFields2"> <input type="text" name="sender" value="e.g. Love from Nick" size="30" maxlength="35" /></a></p> <p class="btn2" > <input type="submit" value="Preview"></p> </form> And this should call up return validate_form(this) before bringing up the php page. Now the validator is just Code: function validate_required(field, alerttxt) { if (field.value == null || field.value == "") { alert(alerttxt); return false; } else { return true; } } function validate_form(thisform) { if (validate_required(thisform.name,"Please specify the receivers name.")==false) { thisform.name.focus(); return false; } if (validate_required(thisform.sender,"Please specify the sender's name.")==false) { thisform.sender.focus(); return false; } } (This is not in the html file, but its own seperate file) I cant see if I have made any mistakes with the variables names or something, or what I am doing wrong. Dont get any errors, just nothing happens if I leave my forms fields blank. Anyone have an idea of whats going on here? cheers I keep getting validation errors for using && as and. I've read to put "&" in place of it, but whenever I do this, the code stops working. I've tried seperate parenths, and still confused. anyone help to make this work and validate at the same time? if (first=="" && last=="") first = last = "Unknown"; if (first == '') document.writeln(last); else if (last == '') document.writeln(first); else document.writeln (last + ", " + first); Hello, I dont know if I am going about this the right way, but.. I am trying to validate an email address. If the email is a valid looking email address, it will render the submit button disabled to prevent dupe's while the rest of the script processes. The email validation portion works, but, the part where it renders the form submit button disabled does not: <script type="text/javascript"> function validate_email(field,alerttxt) { with (field) { apos=value.indexOf("@"); dotpos=value.lastIndexOf("."); if (apos<1||dotpos-apos<2) {alert(alerttxt);return false;} else {return true; submit.disabled = true;} } } function validate_form(thisform) { with (thisform) { if (validate_email(email,"Please enter a valid email address.")==false) {email.focus();return false;} } } </script> Any guidance or help would be apreciated. Hello to everyone i need to validate a form Based on radio buttons and text box my code so far Code: <html> <head> <title>My Page</title> <script type="text/javascript"> function validate(thisform) { document.getElementByName("bank");//text box // validate myradiobuttons radio = -1; for (i=thisform.day.length-1; i > -1; i--) { if (thisform.day[i].checked) { radio = i; i = -1; } } if (radio == -1) { alert("You must select all values for the clock !"); return false; } else { return true; } } //bank code validation if (document.getElementByName("bank").value.length>=6) { return true; } else { alert("you must input maximum 6 digit (123456) !"); return false; } } </script> </head> <body> <form action="form-output.php" method="post" id="form"> <input type="radio" name="day" value="f" onclick="dayofweek(this)" /> Sunday (default) <input type="radio" name="day" value="s" onclick="dayofweek(this)" /> Sun </p> <input type="radio" name="month" value="a" onclick="dateformat(this)" /> 28th March 2010 (default) <input type="radio" name="month" value="b" onclick="dateformat(this)" /> 28 March 2010 <input type="radio" name="month" value="c" onclick="dateformat(this)" /> 28th Mar 2010 <input type="radio" name="month" value="d" onclick="dateformat(this)" /> 28 Mar 2010 <input type="radio" name="month" value="e" onclick="dateformat(this)" /> 28/03/2010 <input type="radio" name="month" value="f" onclick="dateformat(this)" /> 28th March 10 <input type="radio" name="month" value="g" onclick="dateformat(this)" /> 28 March 10 <input type="radio" name="month" value="h" onclick="dateformat(this)" /> 28th Mar 10 <br/> <input type="radio" name="month" value="i" onclick="dateformat(this)" /> 28 Mar 10 <input type="radio" name="month" value="j" onclick="dateformat(this)" /> 28/03/10 <input type="radio" name="month" value="k" onclick="dateformat(this)" /> 28th March <input type="radio" name="month" value="l" onclick="dateformat(this)" /> 28 March <input type="radio" name="month" value="m" onclick="dateformat(this)" /> 28th Mar <input type="radio" name="month" value="o" onclick="dateformat(this)" /> 28 Mar <input type="radio" name="month" value="p" onclick="dateformat(this)" /> 28/03 </p> <input type="radio" name="time" value="a" onclick="timeformat(this)" /> 5:28:12 am (Default) <input type="radio" name="time" value="b" onclick="timeformat(this)" /> 5:28 am <input type="radio" name="time" value="c" onclick="timeformat(this)" /> 5:28:12 <input type="radio" name="time" value="d" onclick="timeformat(this)" /> 5:28 <input type="radio" name="time" value="e" onclick="timeformat(this)" /> 17:28:12 <input type="radio" name="time" value="f" onclick="timeformat(this)" /> 17:28 </p> Input a short Bank Code <input type="text" name="bank" size="10" onblur="JavaScript:alert('You must insert a Bank Code')" /></br> <input type="submit" name="submit" onclick="validate(form);return false;" value="Submit" /> <input type="reset" name="reset" value="reset" /> </form> </body> </html> i need on submit to validate if user select values from 3 radio groups and insert the proper data to text box. if not i want to return the proper alerts in text box also i want when lose focus to validate so i put this Code: onblur="JavaScript:alert('You must insert a Bank Code')" it's ok? Thanks in Advance In my project i have a from which have several fields. The form is <form name="reg" action="payment.jsp" method="post"> ----------- <tr> <td>First name:</td> <td><input type="text" name="firstname"/></td></tr> -------------------------- <input type="submit" value="Next" onclick="fun()" /> ------------ </form> Then to validate the fields i have used JavaScript.They are validating rightly using a alert box. But when i am pressing ok of the alert box the control is passing to the page i have written in action of the form.I want when i will press ok it should come back to the same page.Only if all fields are then it should go to the page refereed in action. Can anyone help me? The JavaScript code is <script type="text/javascript"> function fun() { var x=document.forms["reg"]["firstname"].value; if (x==null || x=="") { alert("First name must be filled out"); } Hi all, I have some problem about validating my form.Infact nothing is happening when clicking the submit button.Can anyone tell me where the problem is.Here are my code. Code: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Create New Customer-PAXWine</title> <style type="text/css"> <!-- body { margin:0 px; padding:0px; } #container { clear: both; float: none; height: 800px; width: 970px; margin-right: auto; margin-left: auto; } #content { background-color: #BC9C85; height: 800px; width: 970px; } #content-title{ padding: 25px 5px 5px 25px; color:#521514; font-family: Arial, "Times New Roman", Times, serif; font-size:10px; } #fieldset{ border:4px solid #E8E4CB; -moz-border-radius:10px; -webkit-border-radius:10px; border-radius:10px; background:#FCFCF9; width:700px; padding:22px 25px 12px 33px; margin:28px; } #legend{ float:left; font-weight:normal; font-size:15px; border:1px solid #fefefe; background:#521514; color:#fff; margin: -33px 0 0 -10px; padding:2px 8px; position:relative; -moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px; display:inherit } #buttons{ margin:25px 370px; } --> </style> <script type="text/javascript"> function echeck(str) { var at = "@" var dot = "." var lat = str.indexOf(at) var lstr = str.length var ldot = str.indexOf(dot) if (str.indexOf(at)==-1) { alert("Invalid E-mail ID") return false; } if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) { alert("Invalid E-mail ID") return false; } if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) { alert("Invalid E-mail ID") return false; } if (str.indexOf(at,(lat+1))!=-1) { alert("Invalid E-mail ID") return false; } if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) { alert("Invalid E-mail ID") return false; } if (str.indexOf(dot,(lat+2))==-1) { alert("Invalid E-mail ID") return false; } if (str.indexOf(" ")!=-1) { alert("Invalid E-mail ID") return false; } return true; } //checkbox function function DoTheCheck() { message = "Your Preference:\n\n" //For each checkbox see if it has been checked, record the value. for (i = 0; i < document.myform.wine.length; i++) if (document.myform.wine[i].checked) { message = message +document.myform.wine[i].value + "\n" } alert(message) } //Created / Generates the captcha function function DrawCaptcha() { var a = Math.ceil(Math.random() * 10)+ ''; var b = Math.ceil(Math.random() * 10)+ ''; var c = Math.ceil(Math.random() * 10)+ ''; var d = Math.ceil(Math.random() * 10)+ ''; var e = Math.ceil(Math.random() * 10)+ ''; var f = Math.ceil(Math.random() * 10)+ ''; var g = Math.ceil(Math.random() * 10)+ ''; var code = a + ' ' + b + ' ' + ' ' + c + ' ' + d + ' ' + e + ' '+ f + ' ' + g; document.myform.txtCaptcha.value = code } // Remove the spaces from the entered and generated code function removeSpaces(string) { return string.split(' ').join(''); } function validateform() { var nic = document.myform.nic.value; var firstname = document.myform.fname.value; var surname = document.myform.sname.value; var phone = document.myform.phone.value; var mail = document.myform.mail.value; var chks = document.getElementsByName('wine[]'); var hasChecked = false; var username = document.myform.uname.value var pass1 = document.myform.pass1.value; var pass2 = document.myform.pass2.value; var str1 = document.myform.txtCaptcha.value; var str2 = document.myform.txtInput.value; var which = document.myform.fname.value; var which1 = document.myform.sname.value; var numericExpression = /^[0-9]+$/; var message = document.getElementById('confirmMessage'); var returnval=false; if (nic.value == "") { window.alert("Please enter your National Identity Card Number."); nic.focus(); return false; } if (firstname.value == "") { window.alert("Please enter your First Name."); fname.focus(); return false; } if (/[^a-z]/gi.test(which.value)) { alert ("Only Alphabets Are Valid In This Field"); which.value = ""; which.focus(); return false; } if (surname.value == "") { window.alert("Please enter your Last Name."); sname.focus(); return false; } if (/[^a-z]/gi.test(which1.value)) { alert ("Only Alphabets Are Valid In This Field"); which1.value = ""; which1.focus(); return false; } if (phone.value == "") { window.alert("Please enter your Phone Number."); phone.focus(); return false; } if (!phone.value.match(numericExpression)) { alert("Phone Number Must Consists of Only Numbers"); phone.focus(); return false; } if (phone.value.length != 7) { alert("Phone number must consist of 7 numbers"); phone.focus(); return false; } if (mail.value == "") { alert("Please Enter your Email Address") mail.focus() return false } if (echeck(mail.value)==false) { mail.value="" mail.focus() return false; } if (chks.length[i].checked) { hasChecked = true; break; } if (hasChecked == false) { alert("Please select at least one preference."); return false; } if (username.value == "") { window.alert("Please enter a username."); uname.focus(); return false; } if (username.value.length < 8) { window.alert("Username must consists of more than 8 character."); uname.focus(); return false; } if (pass1.value == "") { window.alert("Please enter A Password."); pass1.focus(); return false; } if (pass2.value == "") { window.alert("Please Re-enter the password."); pass2.focus(); return false; } if (pass1.value != pass2.value) { window.alert("You did not enter the same password twice. Please re-enter both now."); pass1.focus(); pass1.select(); return false; } if (removeSpaces(str1.value) != removeSpaces(str2.value)) { windows.alert("The registration code did not match the one displayed.Please re-enter the code"); txtInput.focus(); return false; } return window.alert('Registration was Successfull'); } function allowReset() { return window.confirm('Do you really want to clear this form?') } </script> </head> <body> <div id="container"> <div id="content"> <div id="content-title"> <h1>Create an Account</h1> </div> <div id="fieldset"> <div id="legend">Personal Information</div> <form name="myform" action="" onSubmit = "return validateform();" onReset = "return allowReset()" method = "post" action = ""> <table> <tr> <td>NIC:</td> <td><input type="text" id="nic" name="nic" value="" size="15"></td> </tr> <tr> <td>First Name:</td> <td><input type="text" id="fname" name="fname" value="" size="15"></td> </tr> <tr> <td>Surname:</td> <td><input type="text" id="sname" name="sname" value="" size="15"></td> </tr> <tr> <td>Phone:</td> <td><input type="text" id="phone" name="phone" value="" size="15"></td> </tr> <tr> <td>Email address:</td> <td><input type="text" id="mail" name="mail" value="" size="15"></td> </tr> <tr> <td>Preference:</td> <td> <input type="checkbox" name="wine" value="White wine" onclick="DoTheCheck();"/>White wine <input type="checkbox" name="wine" value="Red wine" onclick="DoTheCheck();"/>Red wine <input type="checkbox" name="wine" value="Rose wine" onclick="DoTheCheck();"/>Rose wine </td> </tr> <tr> <td>Sex:</td> <td> <input type="radio" id="sex" value="Male" checked>Male <input type="radio" id="sex" value="Female">Female </td> </tr> <tr> <td>Country:</td> <td> <select name="country"> <option value="none">Select Country</option> <option value="Algeria">Algeria</option> <option value="Argentina">Argentina</option> <option value="Australia">Australia</option> <option value="Bahamas">Bahamas</option> <option value="Brazil">Brazil</option> <option value="Brunei">Brunei</option> <option value="Canada">Canada</option> <option value="China">China</option> <option value="Costa Rica">Costa Rica</option> <option value="Finland">Finland</option> <option value="France">France</option> <option value="Hungary">Hungary</option> <option value="India">India</option> <option value="Indonesia">Indonesia</option> <option value="Italy">Italy</option> <option value="Madagascar">Madagascar</option> <option value="Malaysia">Malaysia</option> <option value="Mauritania">Mauritania</option> <option value="Mauritius">Mauritius</option> <option value="Mexico">Mexico</option> <option value="Netherlands">Mexico</option> <option value="New Zealand">New Zealand</option> <option value="Poland">Poland</option> <option value="Portugal">Portugal</option> <option value="Romania">Romania</option> <option value="Rwanda">Rwanda</option> <option value="Seychelles">Seychelles</option> <option value="Singapore">Singapore</option> <option value="Slovakia">Slovakia</option> <option value="South Africa">South Africa</option> <option value="Spain">Spain</option> <option value="Taiwan">Taiwan</option> <option value="Thailand">Thailand</option> <option value="Tunis">Tunis</option> <option value="United Kingdom">United Kingdom</option> <option value="United States">United States</option> <option value="Uruguay">Uruguay</option> <option value="Vanuatu">Vanuatu</option> <option value="Vatican City">Vatican City</option> <option value="Venezuela">Venezuela</option> <option value="Yemen">Yemen</option> <option value="Zambia">Zambia</option> <option value="Zimbabwe">Zimbabwe</option> </select> </td> </tr> <tr> <td>Username:</td> <td><input type="text" id="uname" name="uname" value="" size="15" ></td> </tr> </table> </div> <div id="fieldset"> <div id="legend">Login Information</div> <table> <tr> <td>Password:</td> <td><input type="password" id="pass1" name="pass1" value="" size="15" /></td> <td> </td> <td>Confirm Password:</td> <td><input type="password" id="pass2" value="" size="15" /></td> </tr> </table> </div> <div id="fieldset"> <div id="legend">Capcha</div> <table> <tr> <td> <input type="text" id="txtCaptcha" style="text-align:center; border:none;font-weight:bold; font-family:Modern"/> </td> </tr> <tr> <td> <input type="text" id="txtInput"/> </td> </tr> <tr> <td> <input type="button" id="btnrefresh" value="Refresh" onclick="DrawCaptcha();" /> </td> </tr> </table> </div> <div id="buttons"> <input type="submit" value="Submit" /> <input type="reset" value="Reset"/> </div> </form> </div> </div> </body> </html> This is a bit of a lazy post but hey, Currently i have an awful lot of checks that run the same check on different variables. Simple Request... Can anyone see an obvious way (which i have clearly missed) to clean up and reduce the amount of code in the below. Code: <? // required code for every page. require($_SERVER['DOCUMENT_ROOT'] . '/scripts/required.php'); // end of required code for every page if(isset($_POST['sbmt'])) { // get variables $new_user = trim($_POST['user']); $new_pass = $_POST['newpass']; $con_pass = $_POST['conpass']; $new_fname = trim($_POST['fname']); $new_email = $_POST['email']; $con_email = $_POST['conemail']; $agree = $_POST['agree']; $level = $_POST['level']; $ip = @$_SERVER['REMOTE_ADDR']; // add slashes $new_user = addslashes($new_user); // encrypt $new_pass_e = hash('ripemd160',$new_pass); $con_pass_e = hash('ripemd160',$con_pass); // check username exists // connect to database $con = mysql_connect(DBHOST, DBUSER, DBPASS); if(!$con) { die('Could not connect: ' . mysql_error());} mysql_select_db(DBNAME, $con); // get row for user $result = mysql_query("SELECT * FROM tUsers WHERE username='$new_user'"); $row = mysql_fetch_array($result); // kill connection mysql_close($con); // check username exists if($row['username']!=null) $user_error = 'Username already in use.<br />'; else $user_error = null; // check email is available // connect to database $con = mysql_connect(DBHOST, DBUSER, DBPASS); if(!$con) { die('Could not connect: ' . mysql_error());} mysql_select_db(DBNAME, $con); // get row for user $result = mysql_query("SELECT * FROM tUsers WHERE email='$new_email'"); $row = mysql_fetch_array($result); // kill connection mysql_close($con); // check email is available if($row['email']!=null) $email_error = 'Email already in use.<br />'; else $email_error = null; // check lengths if(strlen($new_user)<3) $user_len_error = 'Username must be at least 3 characters<br />'; else $user_len_error = null; if(strlen($new_pass)<6) $pass_len_error = 'Password must be at least 6 characters<br />'; else $pass_len_error = null; if(strlen($new_fname)<6) $fname_len_error = 'Your name must be at least 6 characters<br />'; else $fname_len_error = null; // preg matches if(!preg_match('/^[a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/', $new_email)) $email_preg_error = "Email is not valid.<br />"; else $email_preg_error = null; if(!preg_match('/[a-zA-Z]+\s+[a-zA-Z]+/',$new_fname)) $fname_preg_error = 'Name must containt at least one space.<br />'; else $fname_preg_error = null; // check matches if($new_pass != $con_pass) $pass_match_error = 'The passwords do not match.<br />'; else $pass_match_error = null; if($new_email != $con_email) $email_match_error = 'The emails do not match.<br />'; else $email_match_error = null; // build error list $errorlist = $user_error; $errorlist .= $email_error; $errorlist .= $user_len_error; $errorlist .= $pass_len_error; $errorlist .= $fname_len_error; $errorlist .= $email_preg_error; $errorlist .= $fname_preg_error; $errorlist .= $pass_match_error; $errorlist .= $email_match_error; // set expirey to a month $expire = 0; // set error list cookie setcookie('errorlist',$errorlist,$expire,'/'); // reload register.php header('Location:' . URL . '/register.php'); } ?> The required file is just a series of defines for items like the dbhost, dbusername, dbname, url etc etc. Cheers p.s. I want to add an if statement for if $errorlist=null then do bla else bla... in order for errorlist to be null... do i actually need to define the individual error messages as null. That could get rid of a lot of: else $<error name>=null; I'm pretty sure I can but i'd like to check first. Hi i got a script that validates the fields username and password, can anybody check if this code for checking the username and password for illegal characters is ok or if i need to change it. thanks kimbo Code: addLoadEvent (function() { document.entryform.onsubmit = validateEntry; }); function validateEntry() { var errorMsg = ""; if (document.getElementById("username").value <= "") { errorMsg += "Please enter your username.\n"; } if (document.getElementById("password").value == "") { errorMsg += "Please enter your email password\n"; } else { if (!document.getElementById("username").value.match(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/)) { errorMsg += "invalid characters.\n"; } if (!document.getElementById("password").value.match(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/)) { errorMsg += "invalid characters.\n"; } } if (errorMsg == "") { return true; } else { alert(errorMsg); return false; } } function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { if (oldonload) { oldonload(); } func(); } } } Code: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>New Page 2</title> </head> <script type="text/javascript"> var strWord = document.myForm.txtWord.value; function validateWord() { while(strWord == document.formname.myForm.value.length > 8 && var ichars = "PJ" ); { alert ("OK."); } } </SCRIPT> <form name="myForm" action="" method="" onsubmit="return false"> <p> <input name="txtWord" size="25" value="Enter Word Here"> </p> <p> <input type="button" value="Validate The Word" name="cmdValidateWord" onclick ="validateWord()"> </p> </html> Hi, I'm having trouble getting this code to work. It needs to check if the user has entered the correct characters into a field. A valid word should have a P at the start, and contain a J somewhere in it. If the word is valid, a box pops up saying "OK" once the user has clicked the ValidateWord button. It also needs to keep this kind of structure (ie. a while construct & validated through pressing a button). This is purely for personal education about performance of "while" constructs for field validation. Any help is hugely appreciated. Please help, my validation is not working: I added this to my HEAD Code: <script> function validate(){ var temp if (document.form.name.value=="") { alert("Please select a customer.") return false } return true } </script> then here is my form: Code: <form action="send-massemail-script.php" method="post" name="form" onsubmit="return validate()"> <fieldset> <!-- Set class to "column-left" or "column-right" on fieldsets to divide the form into columns --> <p> <label>Customer Name</label> <select name="name" id="name"> <option value="Please select name">Please select name</option> <?php while($row1 = mysql_fetch_array($result3)) { echo '<option value="'.$row1['id'].'">'.$row1['customer_name'].'</option>'; } ?> </select> </p> <p> <label>Email Title</label> <input class="text-input small-input" type="text" id="small-input" name="EmailTitle" /> </p> <p> <label>Email Body</label> <textarea rows="15" cols="79" name="EmailBody" id="textarea" class="text-input textarea wysiwyg" style="width: 930px; height: 247px;"></textarea> </p> <p> <input class="button" type="submit" value="Send Email" /> </p> </fieldset> <div class="clear"></div><!-- End .clear --> </form> im suppose to validate an ID text field so that is it mandatory, and must be 6 numeric digits. The code i have for the ID field is: Code: <form id="ThisForm"> <label for="emId"> Employee ID: </label></td> <input type="text" name="empID" id="emId" ;"/> </form> I'm beginner to javascript and really has no idea what to do, can someone help pls. Hello there. I am trying to validate data for text boxes, radios and check-boxes which are stored in an object. Can anyone suggest how I might go about doing so? Maybe there is a website to learn from? I've had a good look around myself but haven't come across what I'm looking for unfortunately. Thank-you. |