SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Feb 2013
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    one last issue for now is, i'm trying to make a javascript for password validation, and this is what i currently have... i'm kind of stuck now and not sure on what to do next, could you kindly check this??

    this is my regvalidation.js file

    Code:
    function formValidation()  
    {  
     
    var passid = document.registration.password;  
    var uname = document.registration.username;  
      
    var uemail = document.registration.email;  
    
    
    
    if(passid_validation(passid,7,12))  
    {  
    if(allLetter(uname))  
    {  
    if(ValidateEmail(uemail))  
    {   
    }   
    }  
    }    
    return false;  
    }  
    
    function passid_validation(passid,mx,my)  
    {  
    var passid_len = passid.value.length;  
    if (passid_len == 0 ||passid_len >= my || passid_len < mx)  
    {  
    alert("Password should not be empty / length be between "+mx+" to "+my);  
    passid.focus();  
    return false;  
    }  
    return true;  
    }  
    
    
    function allLetter(uname)  
    {   
    var letters = /^[A-Za-z]+$/;  
    if(uname.value.match(letters))  
    {  
    return true;  
    }  
    else  
    {  
    alert('Username must have alphabet characters only');  
    uname.focus();  
    return false;  
    }  
    }  
    
    
    function ValidateEmail(uemail)  
    {  
    var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;  
    if(uemail.value.match(mailformat))  
    {  
    return true;  
    }  
    else  
    {  
    alert("You have entered an invalid email address!");  
    uemail.focus();  
    return false;  
    }  
    }

    and this is my registration form...

    Code:
    <script src="js/regvalidation.js"></script>  
    onload="document.registration.userid.focus();">  
    <p class="lead">REGISTER</p> 
    <p>Use tab keys to move from one input field to the next.</p>  
    <form action="register.php" method="post" name='registration' onSubmit="return formValidation();">  
    <fieldset>
            <div class="control-group">
                <input autofocus name="username" placeholder="Username" type="text"/>
            </div>
            <div class="control-group">
                <input name="password" placeholder="Password" type="password"/>
            </div>
            <div class="control-group">
                <input name="confirmation" placeholder="Confirm password" type="password"/>
            </div>
            <div class="control-group">
                <input name="email" placeholder="Enter Email" type="text"/>
            </div>
            
            <div class="control-group">
                <input name="security" placeholder="Security Keyword" type="text"/>
            </div>
            <div class="control-group">
                <button type="submit" class="btn">Register</button>
            </div>
        </fieldset>
    </form>  
    <div>
        or <a href="login.php">log in</a>
    </div>

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,123
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Okay, so from my initial testing, the only issues I found are as follows:
    1) make sure onload="document.registration.userid.focus();"> is attached to a body tag
    2) Add return true; inside the if (ValidateEmail(uemail)) block

    Code:
    function formValidation()  
    {  
     
    var passid = document.registration.password;  
    var uname = document.registration.username;  
      
    var uemail = document.registration.email;  
    
    
    
    if(passid_validation(passid,7,12))  
    {  
    if(allLetter(uname))  
    {  
    if(ValidateEmail(uemail))  
    {   
       return true;
    }   
    }  
    }    
    return false;  
    }
    Without the return true, even once the data passes validation, it won't submit the form. With the return true, it allows the form to submit once the validation passes.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •