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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    Regular Coder Ludatha's Avatar
    Join Date
    Jan 2008
    Posts
    250
    Thanks
    51
    Thanked 5 Times in 5 Posts

    eregi, How to I change this...

    PHP Code:
    if (!eregi('^[a-zA-Z]+[a-zA-Z0-9_-]*@([a-zA-Z0-9]+){1}(\.[a-zA-Z0-9]+){1,2}'stripslashes(trim($_POST['email'])) )) { 
    This is my current code, but it doesnt allow emails with a . before the @ symbol.
    How can I change this to allow it.

    This is NOT allowed:
    adam.smells@bobo.com
    chickin.smells.funny@gmail.com
    etc.

    This IS allowed:
    adam@bob.com
    hello@goodbye.co.uk
    etc.

    Note: The emails are just examples :P

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    PHP Code:
    if (!eregi('^[a-zA-Z]+[a-zA-Z0-9_-.]*@([a-zA-Z0-9]+){1}(\.[a-zA-Z0-9]+){1,2}'stripslashes(trim($_POST['email'])) )) { 

  • #3
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    PHP Code:
    if (!eregi(^[a-z]+[a-z0-9._-]*@ ... 

    Just put the dot in there, like above.

    Incidentally, the 'i' in eregi means 'case-insensitive', so you can get by without the range of caps, as illustrated above.
    Last edited by tomws; 04-25-2008 at 03:56 PM. Reason: oops on quoting

  • #4
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Quote Originally Posted by Mwnciau View Post
    PHP Code:
    if (!eregi('^[a-zA-Z]+[a-zA-Z0-9_-.]*@([a-zA-Z0-9]+){1}(\.[a-zA-Z0-9]+){1,2}'stripslashes(trim($_POST['email'])) )) { 
    That one will probably result in a range error because the dash is between two terms.

  • #5
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Ludatha View Post
    PHP Code:
    if (!eregi('^[a-zA-Z]+[a-zA-Z0-9_-]*@([a-zA-Z0-9]+){1}(\.[a-zA-Z0-9]+){1,2}'stripslashes(trim($_POST['email'])) )) { 
    PHP Code:
    if (!eregi('^[a-zA-Z]+[\.a-zA-Z0-9_-]*@([a-zA-Z0-9]+){1}(\.[a-zA-Z0-9]+){1,2}'stripslashes(trim($_POST['email'])) )) { 
    add a \. in second []

    Edit: This is a wrong way to validate email address, look into rfc822 for details.
    For example me@you@is.valid pass this regex.

    regards
    Last edited by oesxyl; 04-25-2008 at 04:05 PM.

  • Users who have thanked oesxyl for this post:

    Ludatha (04-25-2008)

  • #6
    Regular Coder Ludatha's Avatar
    Join Date
    Jan 2008
    Posts
    250
    Thanks
    51
    Thanked 5 Times in 5 Posts
    Thanks oesxyl, it works fine, if the email is not valid, they will not get an email so ill kep it as that
    Last edited by Ludatha; 04-25-2008 at 04:23 PM.

  • #7
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Ludatha View Post
    I tried that before, but this is what I get:

    Warning: eregi() [function.eregi]: REG_ERANGE in /home/ludatha/public_html/signup.php on line 38
    Error!
    The following error(s) occured:
    - Please provide a valid email address.

    Code:
     if (!eregi('^[a-zA-Z]+[\.a-zA-Z0-9_-]*@([a-zA-Z0-9]+){1}(\.[a-zA-Z0-9]+){1,2}', stripslashes(trim($_POST['email'])) )) {
    That is line 38
    this way, see also tomws post about range error.
    Did you notice that me@you@is.valid pass the regex?

    regards

  • #8
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Quote Originally Posted by oesxyl View Post
    Did you notice that me@you@is.valid pass the regex?
    That example fails your pattern, not passes, when I do this...
    PHP Code:
    $pattern '^[a-zA-Z]+[\.a-zA-Z0-9_-]*@([a-zA-Z0-9]+){1}(\.[a-zA-Z0-9]+){1,2}';
    $string "me@you@is.valid";

    if ( !
    eregi($pattern,$string) )
    {
        echo 
    "no\n";

    // end: if
    else //
    {
        echo 
    "yes\n";

    // end: else 
    ???

    Incidentally, would it be wise to have a '$' at the end?
    Last edited by tomws; 04-25-2008 at 04:31 PM. Reason: wrong code tags

  • #9
    Regular Coder Iszak's Avatar
    Join Date
    Jun 2007
    Location
    Perth, Western Australia
    Posts
    332
    Thanks
    2
    Thanked 58 Times in 57 Posts
    Ugh you are forgetting the most important thing. The best way to validate an email is to send an email to it and get them to check for it but if you want one of the best email regex here they are. http://fightingforalostcause.net/mis...mail-regex.php

  • #10
    New Coder
    Join Date
    Mar 2008
    Posts
    18
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by oesxyl View Post
    Edit: This is a wrong way to validate email address, look into rfc822 for details.
    For example me@you@is.valid pass this regex.

    regards
    That doesn't generate a match... anyway, here's a cleaner way to do this one:

    PHP Code:
    if (!eregi('^\w+(\.|\w|-)*@(\w+)(\.\w{2,}\.?(\w{2,})?)'stripslashes(trim($_POST['email'])) )) { 
    \w = [a-zA-Z0-9_]

  • #11
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by tomws View Post
    That example fails your pattern, not passes, when I do this...
    PHP Code:
    $pattern '^[a-zA-Z]+[\.a-zA-Z0-9_-]*@([a-zA-Z0-9]+){1}(\.[a-zA-Z0-9]+){1,2}';
    $string "me@you@is.valid";

    if ( !
    eregi($pattern,$string) )
    {
        echo 
    "no\n";

    // end: if
    else //
    {
        echo 
    "yes\n";

    // end: else 
    ???

    Incidentally, would it be wise to have a '$' at the end?
    it print a 'no' or a 'yes'?

    I realise that when I said 'pass' was a little ambigue, but this regex will consider the email address I post as valid email that means don't work.

    agree with you that a $ must be used, .

    regards

  • #12
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Iszak View Post
    Ugh you are forgetting the most important thing. The best way to validate an email is to send an email to it and get them to check for it but if you want one of the best email regex here they are. http://fightingforalostcause.net/mis...mail-regex.php
    you can't validate a email address using only regex.
    agree with first, suggestion,

    Quote Originally Posted by spaz View Post
    That doesn't generate a match... anyway, here's a cleaner way to do this one:

    PHP Code:
    if (!eregi('^\w+(\.|\w|-)*@(\w+)(\.\w{2,}\.?(\w{2,})?)'stripslashes(trim($_POST['email'])) )) { 
    \w = [a-zA-Z0-9_]
    did you test this?

    regards

  • #13
    New Coder
    Join Date
    Mar 2008
    Posts
    18
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by oesxyl View Post
    did you test this?

    regards
    Only in EditPad Pro

  • #14
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by spaz View Post
    Only in EditPad Pro
    for me don't work, was also my first attempt to make the regex more simple,

    regards

  • #15
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Quote Originally Posted by oesxyl View Post
    it print a 'no' or a 'yes'?
    It prints 'no'.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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