Web Analytics Made Easy -
StatCounter Verifying form fields - CodingForum

Announcement

Collapse
No announcement yet.

Verifying form fields

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Verifying form fields

    How can I verify form fields for different things? Can anyone show me a script?

    I'm wanting the username to contain letters and numbers only
    password the same, and check that the verify password is the same
    email address contains the @
    and a textarea that contains no website addresses or email address

    Is this possible?

    Thanks

  • #2
    function validate() {
    var theForm = document.formName;

    if ( ! /[a-zA-Z0-9]+/.test(theForm.user.value) ) {
    alert('Username may contain only letters or numbers');
    return false;
    }
    if ( ! /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z0-9]+)(\]?)$/.test(theForm.email.value) {
    alert('email address is invalid');
    return false;
    }
    if ( ( ! /[a-zA-Z0-9]+/.test(theForm.password.value) ) || ( theForm.password.value != theForm.password2.value ) {
    alert('Please enter your password again');
    return false;
    }
    if ( /[a-zA-Z0-9]+/.test(theForm.textbox.value) ) {
    alert('Text box may not contain email addresses');
    return false;
    }
    if ( /(http|ftp|https):\/\/[\w]+(.[\w]+)([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/.test(theForm.textbox.value) ) {
    alert('Text box may not contain website addresses');
    return false;
    }
    }

    that was real fast, off the top of my head. you may have to check that website RE. i found it on some website somewhere, and haven't had a chance to test it myself.
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

    Comment


    • #3
      Can you check the form here and see what's wrong? It's saying username is not defined

      http://chatterspics.com/register

      You only get one attempt with the username though, as it registers straight away.

      Thanks

      Comment


      • #4
        function validate() {
        var theForm = document.formName;

        you forgot to customize that.
        bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

        i am a loser geek, crazy with an evil streak,
        yes i do believe there is a violent thing inside of me.

        Comment


        • #5
          Thanks It's working now, sort of.

          The one for the textarea, the one to disable websites and email addresses, well if you put a website in, it tells you email addresses can't be used. Can this be fixed easily? If it can't, I'll just modify the alert for the email

          Thanks again

          Comment


          • #6
            whoops, made a mistake while i was copying and pasting. change the no email in textbox to the following:

            if ( ! /.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z0-9]+)(\]?)/.test(theForm.textbox.value) {
            alert('Text box may not contain email addresses');
            return false;
            }
            bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

            i am a loser geek, crazy with an evil streak,
            yes i do believe there is a violent thing inside of me.

            Comment


            • #7
              Back. Thanks for your help so far

              It's now saying that I can't put an email address in, even if I don't put one in or put no text in.

              I'd try and figure it out but this means nothing to me.

              Comment


              • #8
                Huh? It seems to be working for me...

                <edit>Although I get this error:
                Warning: Unable to open 'none' for reading: No such file or directory in /home/chatterspics/public_html/register/index.php on line 188</edit>
                Former ASP Forum Moderator - I'm back!

                If you can teach yourself how to learn, you can learn anything. ;)

                Comment


                • #9
                  Yeah, I took out the email thing.

                  I've posted my question to that error in the php forum. Everything works ok, just throwing that error for some reason.

                  Comment


                  • #10
                    once again, i made an error during my copy and paste (sorry, i'm GMT + 1, it was late for me.)

                    this is right:

                    if ( /.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z0-9]+)(\]?)/.test(theForm.textbox.value) {
                    alert('Text box may not contain email addresses');
                    return false;
                    }
                    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

                    i am a loser geek, crazy with an evil streak,
                    yes i do believe there is a violent thing inside of me.

                    Comment


                    • #11
                      lol thanks Joh6nn I'll try it later

                      Comment

                      Working...
                      X