Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts

    E-Mail Validation ??

    Hi I would like to know how I can validate the e-mail address submitted from my form. I have the following for some of the fields in my form to check if they are empty:

    if ($fields{'County'} eq "") {
    dienice("Please go back and enter your county. Then re-submit the form.");
    }

    How do I do it for an e-mail address so it checks if it has been entered properly, i.e. yourname@yahoo.com.
    I done this in javascript before using regular expressions. But I have no idea in here.

    Can anyone help ??

    Thanks

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    the Netherlands
    Posts
    215
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try this one:

    if($emailaddress !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/) {
    dienice("Please go back and enter your e-mail address right. Then re-submit the form.");
    }

    Hope that's enough...

    Mzzl, Chris

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Perl's best known features are its regular expressions, which are generally considered the best. I think I'm right in saying that JavaScript's regexes are little more than a copy, correct me if I'm wrong though..

    You do pattern matching usually with the =~ operator. Here you'd use something like this:
    Code:
    unless ($fields{'Email'} =~ /(regex goes here)/) {
    dienice("Dodgy email given");
    }
    To do the test..
    Hope that helps a bit.

  • #4
    Regular Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks

    Yer that looks good, just want I wanted.

    Thanks chrisvmarle & mouldy_goat



  •  

    Posting Permissions

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