Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 2 of 2
  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    23
    Member #
    25361
    Hi,
    Please help me to correct this form validation code.it is not working when a field is left blank.Actually it fails to work.Here is it.

    <script type="text/javascript">
    function validateForm()
    {

    function CheckEmail()
    var x=document.frmone.email.value;
    var atpos=x.indexOf("@");
    var dotpos=x.lastIndexOf(".");
    if(atpos<1 || dotpos<atpos+2 ||x.length>30){
    alert("not a valide email address");
    return false
    }


    function Checkempty()
    {
    var x=document.frmone.fname.value;
    if(x==null || x==""){
    alert("username is required");
    return false
    }

    Checkusername()
    {
    var user=document.f1.name.value;
    var illegalchars=^W/; // allows only letters,numbers and underscorse
    if(user.value==""){
    alert("You did not enter ausername");
    return false
    }

    if(illegalchars.test(user.value)){
    alert("You did not enter ausername");
    return false
    }
    if(user.value.length<5 || user.value.length>30){
    alert("username is either less than 5 or more than 30);
    return false
    }
    }
    </script>
    <form name="frmone" method="post" action="" onsubmit="return validateForm()"/>
    Email: <input type="text" name="email"/>
    Empty: <input type="text" name="fname"/>
    username: <input type="text" name="name"/>
    <input type="submit" value="submit form"/>
    </form>

    Please help.
    Thanks.
    Clement Osei.

  2.  

  3. #2
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    First of all, you can't put functions inside of functions like that. You can call functions. But you can't put them inside of functions like that. So the easiest way to solve your problem may be just to remove the function lines and their closing brackets and get that to work.

    Second, your user variable points to a form that doesn't exist.

    If you're going to take code from other sites like you seem to have done, take it in small pieces so you can understand and debug it more easily.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:16 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com