1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Forms field format

Discussion in 'Software Development' started by lola2001, Sep 25, 2003.

Thread Status:
Not open for further replies.
Advertisement
  1. lola2001

    lola2001 Thread Starter

    Joined:
    Jan 29, 2001
    Messages:
    1,972
    Is there a way to make a form field that will verify that the correct information is typed in. For instance I have a form field that asks for a phone number, including the area code and also a field that asks for an email address. I want to make sure that the correct format is typed in and if nothing is typed in those fields then the page should be refreshed with a message saying they missed a field. Am I making any sense here? Thanks.

    I'm using Dreamweaver.
     
  2. Rockn

    Rockn

    Joined:
    Jul 29, 2001
    Messages:
    21,334
    You need to write a java function to validate the form elements and that will fire when the form is dubmitting using the forms onSubmit event. Here's a simple one for an email address

    PHP:
    function ValidateForm(formname)
    if(
    form.Email.value == "")
        { 
            
    alert('You must type in an Email address'
            
    formname.Email.focus();
            return 
    false;

    else if(
    form.Email.value.indexOf('@')== -1)
        {
            
    alert('Your Email address is missing an @ symbol'
            
    formname.Email.focus();
            return 
    false;
        
    //if the EmailAddrs does not contain a full stop
        
    }
    else if(
    form.Email.value.indexOf('.')== -1)
        {
            
    alert('Your Email address is missing a period'
            
    formname.Email.focus();
            return 
    false;
        }
     
  3. lola2001

    lola2001 Thread Starter

    Joined:
    Jan 29, 2001
    Messages:
    1,972
    Ok, thanks. I'll use that. Shouldn't there be something in Dreamweaver that would make it easier though?
     
  4. brendandonhu

    brendandonhu

    Joined:
    Jul 8, 2002
    Messages:
    14,681
    If you have a language that supports Regular Expressions, that could give you much better validation.
     
  5. lola2001

    lola2001 Thread Starter

    Joined:
    Jan 29, 2001
    Messages:
    1,972
    LOL. Brendan..I have NO idea what you just said!
     
  6. brendandonhu

    brendandonhu

    Joined:
    Jul 8, 2002
    Messages:
    14,681
    If your server has PHP, heres how you can validate a phone number (I just made this real quick, and im bad at regexps, so its probably not perfect. It doesn't like international numbers, or people that put their area code in parenthesis).

    PHP:
    if(ereg("^([2-9]{3})(-?)([0-9]{3})(-?)([0-9]{4})$"$phone))
    {echo(
    "$phone is a valid phone number");}
    else {
    "$phone is not a valid phone number");}
    It will validate a number that
    -Starts with 3 digits, 2-9
    -Optionally a - between area code + first 3 digits of number
    -3 Digits 0-9
    -Optionally a - between first 3 digits and last 4 digits of number
    -4 digits, 0-9
     
  7. lola2001

    lola2001 Thread Starter

    Joined:
    Jan 29, 2001
    Messages:
    1,972
    Thanks brendan but you didn't have to go to all that work. I don't know a thing about PHP other then yes, the server does support it. I've been trying to learn a bit about it on the internet but I can't really find anything for beginners who know NOTHING. Oh well. I will keep this info though for the future. Thanks.
     
  8. brendandonhu

    brendandonhu

    Joined:
    Jul 8, 2002
    Messages:
    14,681
    May I ask what you are using to process the form?
    If your using another language (Perl, ASP, whatever), I'm sure you can validate a phone number in that language.
    If your just using a mailto: command or something, I HIGHLY reccommend you switch to PHP. Its much more powerful & reliable. You don't even need to learn the language to process a form, there are ready-made scripts for this.
     
  9. lola2001

    lola2001 Thread Starter

    Joined:
    Jan 29, 2001
    Messages:
    1,972
    I'm just using HTML. I'm just using "insert form" in dreamweaver, then using FormMail from the server. It's just a small little form with a few fields but the client whats to make sure the use puts in an actual phone number and email address. I will switch to PHP when I figure it out. Thanks for the help.
     
  10. brendandonhu

    brendandonhu

    Joined:
    Jul 8, 2002
    Messages:
    14,681
  11. lola2001

    lola2001 Thread Starter

    Joined:
    Jan 29, 2001
    Messages:
    1,972
    Great! Thanks so much!
     
  12. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/167397

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice