Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. form validation

form validation

Scheduled Pinned Locked Moved JavaScript
javascriptcomregexquestion
5 Posts 3 Posters 0 Views 1 Watching
  • 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.
  • T Offline
    T Offline
    therainking78
    wrote on last edited by
    #1

    I had this form validating now it won't even run the first function. Any suggestions?

    // JavaScript Document
    function formValidation()
    {
    var uid = document.registration.userid;
    var uname = document.registration.username;
    var uadd = document.registration.address;
    var uzip = document.registration.zip;
    var uemail = document.registration.email;
    if(userid_validation(uid))
    {
    if(allLetter(uname))
    {
    if(alphanumeric(uadd))
    {
    if(allnumeric(uzip))
    {
    if(ValidateEmail(uemail))
    {
    }
    }
    }
    }
    return false;
    }
    function userid_validation(uid)
    {
    var letters = /^[A-Za-z]+$/;
    var uid_len = uid.value.length;
    if (uid.value.match(letters))
    {
    return true;
    }
    else
    {
    alert("The First Name can not be empty/must contain only letters");
    uid.focus();
    return false;
    }
    }
    function allLetter(uname)
    {
    var letters = /^[A-Za-z]+$/;
    if (uname.value.match(letters))
    {
    return true;
    }
    else
    {
    alert("The Last Name can not be empty/must contain only letters");
    uname.focus();
    return false;
    }
    }
    function alphanumeric(uadd, num)
    {
    var uadd_len = uadd.value.length;
    var numbers = /^[0-9]+$/;
    if (uadd.value.match(numbers))
    {
    return true;
    }
    else
    {
    alert("Your phone number must have a 10 digits all numbers");
    uadd.focus();
    return false;
    }
    }
    function allnumeric(uzip)
    {
    var numbers = /^[0-9]+$/;
    if (uzip.value.match(numbers))
    {
    return true;
    }
    else
    {
    alert("You must fill in your ZIP code with five numeric characters");
    uzip.focus();
    return false;
    }
    }
    function ValidateEmail(uemail)
    {
    var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
    if(uemail.value.match(mailformat))
    {
    alert("Form Succesfully Submitted");
    window.location.reload();
    return true;
    }
    else
    {
    alert("You have entered an invalid email address!");
    uemail.focus();
    return false;
    }

    }

    chrishoy78@gmail.com

    L B 2 Replies Last reply
    0
    • T therainking78

      I had this form validating now it won't even run the first function. Any suggestions?

      // JavaScript Document
      function formValidation()
      {
      var uid = document.registration.userid;
      var uname = document.registration.username;
      var uadd = document.registration.address;
      var uzip = document.registration.zip;
      var uemail = document.registration.email;
      if(userid_validation(uid))
      {
      if(allLetter(uname))
      {
      if(alphanumeric(uadd))
      {
      if(allnumeric(uzip))
      {
      if(ValidateEmail(uemail))
      {
      }
      }
      }
      }
      return false;
      }
      function userid_validation(uid)
      {
      var letters = /^[A-Za-z]+$/;
      var uid_len = uid.value.length;
      if (uid.value.match(letters))
      {
      return true;
      }
      else
      {
      alert("The First Name can not be empty/must contain only letters");
      uid.focus();
      return false;
      }
      }
      function allLetter(uname)
      {
      var letters = /^[A-Za-z]+$/;
      if (uname.value.match(letters))
      {
      return true;
      }
      else
      {
      alert("The Last Name can not be empty/must contain only letters");
      uname.focus();
      return false;
      }
      }
      function alphanumeric(uadd, num)
      {
      var uadd_len = uadd.value.length;
      var numbers = /^[0-9]+$/;
      if (uadd.value.match(numbers))
      {
      return true;
      }
      else
      {
      alert("Your phone number must have a 10 digits all numbers");
      uadd.focus();
      return false;
      }
      }
      function allnumeric(uzip)
      {
      var numbers = /^[0-9]+$/;
      if (uzip.value.match(numbers))
      {
      return true;
      }
      else
      {
      alert("You must fill in your ZIP code with five numeric characters");
      uzip.focus();
      return false;
      }
      }
      function ValidateEmail(uemail)
      {
      var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
      if(uemail.value.match(mailformat))
      {
      alert("Form Succesfully Submitted");
      window.location.reload();
      return true;
      }
      else
      {
      alert("You have entered an invalid email address!");
      uemail.focus();
      return false;
      }

      }

      chrishoy78@gmail.com

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Your first block of if statements does not seem correct. It can either return false or fall through to the remaining functions.

      One of these days I'm going to think of a really clever signature.

      T 1 Reply Last reply
      0
      • T therainking78

        I had this form validating now it won't even run the first function. Any suggestions?

        // JavaScript Document
        function formValidation()
        {
        var uid = document.registration.userid;
        var uname = document.registration.username;
        var uadd = document.registration.address;
        var uzip = document.registration.zip;
        var uemail = document.registration.email;
        if(userid_validation(uid))
        {
        if(allLetter(uname))
        {
        if(alphanumeric(uadd))
        {
        if(allnumeric(uzip))
        {
        if(ValidateEmail(uemail))
        {
        }
        }
        }
        }
        return false;
        }
        function userid_validation(uid)
        {
        var letters = /^[A-Za-z]+$/;
        var uid_len = uid.value.length;
        if (uid.value.match(letters))
        {
        return true;
        }
        else
        {
        alert("The First Name can not be empty/must contain only letters");
        uid.focus();
        return false;
        }
        }
        function allLetter(uname)
        {
        var letters = /^[A-Za-z]+$/;
        if (uname.value.match(letters))
        {
        return true;
        }
        else
        {
        alert("The Last Name can not be empty/must contain only letters");
        uname.focus();
        return false;
        }
        }
        function alphanumeric(uadd, num)
        {
        var uadd_len = uadd.value.length;
        var numbers = /^[0-9]+$/;
        if (uadd.value.match(numbers))
        {
        return true;
        }
        else
        {
        alert("Your phone number must have a 10 digits all numbers");
        uadd.focus();
        return false;
        }
        }
        function allnumeric(uzip)
        {
        var numbers = /^[0-9]+$/;
        if (uzip.value.match(numbers))
        {
        return true;
        }
        else
        {
        alert("You must fill in your ZIP code with five numeric characters");
        uzip.focus();
        return false;
        }
        }
        function ValidateEmail(uemail)
        {
        var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
        if(uemail.value.match(mailformat))
        {
        alert("Form Succesfully Submitted");
        window.location.reload();
        return true;
        }
        else
        {
        alert("You have entered an invalid email address!");
        uemail.focus();
        return false;
        }

        }

        chrishoy78@gmail.com

        B Offline
        B Offline
        bVagadishnu
        wrote on last edited by
        #3

        therainking78 wrote:

        if(ValidateEmail(uemail)) {

        I don't see a closing '}' for this '{'

        Schenectady? What am I doing in Schenectady?

        T 1 Reply Last reply
        0
        • L Lost User

          Your first block of if statements does not seem correct. It can either return false or fall through to the remaining functions.

          One of these days I'm going to think of a really clever signature.

          T Offline
          T Offline
          therainking78
          wrote on last edited by
          #4

          Thanks a ton I finally put all validated that form. Good call.

          1 Reply Last reply
          0
          • B bVagadishnu

            therainking78 wrote:

            if(ValidateEmail(uemail)) {

            I don't see a closing '}' for this '{'

            Schenectady? What am I doing in Schenectady?

            T Offline
            T Offline
            therainking78
            wrote on last edited by
            #5

            Thanks I turned on brace matching for vs2010 and picked up on it. Appreciate it. :)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups