Navigation

    ask avan logo
    • Register
    • Login
    • Search
    • Categories
    • Unsolved
    • Solved

    Javascript Registration Form Validation

    Javascript + jQuery
    javascript validation
    2
    2
    8
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • W
      willaeng last edited by avan

      Sorry I have been really struggling with this. I have more codes, but can't get pass the username yet. It wouldn't even send an alert. Below is just a portion of what I have. Thanks in advance. I just need suggestion on how to get first field (username) to validate and I can go from there.

      function validateForm() {
      
          var userId = document.myForm.userName.value;
          var password = document.myForm.passwordOne.value;
         var passwordVerify = document.myForm.passwordTwo.value;
          var fName = document.myForm.firstName.value;
          var lName = document.myForm.lastName.value;
          var emailAdd = document.myForm.email.value;
          var phone = document.myForm.phonenumber.value;
      
          if (uName(userId)) {
              if (validatePassword(password)) {
                  if (passwordCheck(password, passwordVerify)) {
                      if (onlyLetters(fName)) {
                          if (onlyLetters(lName)) {
                              if (validateEmail(emailAdd)) {
                                  if (phonenumber(phone)) {
                                  }
                              }
                          }
                      }
                  }
              }
          }
          return false;
      }
      
      
      function uName(userId){
      
          var userId_len = userId.value.length;
          var alphaNumber = /^[\w ]+$/;
      
          if (userId_len == 0)
          {
              alert("User Id should not be empty");
              userID.focus();
              return false;
          }
          else if (userId.value.match(alphaNumber)) {
              return true;
          }
          else {
              alert("User Id should be alphanumeric");
              userId.focus();
              return false;
          }
          }
      Reply Quote 0
        1 Reply Last reply

      • avan
        avan last edited by avan

        Hey @willaeng

        I would start off by not calling on value twice. You call on value here:

        var userId = document.myForm.userName.value;

        and again here:

        var userId_len = userId.value.length;
        ...
        else if (userId.value.match(alphaNumber)) {
        

        Try removing the extra calls on .value and then go from there.

        Reply Quote 0
          1 Reply Last reply

        • avan
          avan last edited by avan

          Hey @willaeng

          I would start off by not calling on value twice. You call on value here:

          var userId = document.myForm.userName.value;

          and again here:

          var userId_len = userId.value.length;
          ...
          else if (userId.value.match(alphaNumber)) {
          

          Try removing the extra calls on .value and then go from there.

          Reply Quote 0
            1 Reply Last reply

          • First post
            Last post