[RESOLVED] Need best way to remove char from Email Address
Results 1 to 12 of 12

Thread: [RESOLVED] Need best way to remove char from Email Address

  1. #1
    phpMaster
    Join Date
    Jun 2005
    Location
    Europe
    Posts
    3,009

    resolved [RESOLVED] Need best way to remove char from Email Address

    Have an application with sign up and email activation.
    Database will look for email and not allow more than one of each email.
    I use strtolower() on the email submitted. Along with php filter validate email.

    But here is my problem.
    Suppose one sign up is submitted: johnsmith@yahoo.com
    Second time same user submits: john.smith@yahoo.com
    The third time is submitted this: jo..hnsm.ith@yahoo.com

    The Database will not find the matching duplicate!

    How can I remove all "." in john.smith
    but at the same not remove the "." in yahoo.com?

    I guess this is suitable for preg_match() with a regex.
    Apache-2.4.28 (Win64) / PHP-7.1.10 / MySQL-5.7.19 / phpMyAdmin-4.7.4

  2. #2
    Settled 4 red convertible dalecosp's Avatar
    Join Date
    Jul 2002
    Location
    Accelerating Windows at 9.81 m/s....
    Posts
    8,522
    "johnsmith@yahoo.com" is valid. "john.smith@yahoo.com" is also valid. How can you be certain they are duplicated addresses?

    "jo..hn.sm.ith@yahoo.com" isn't valid. Two "." in a row are not allowed, unless quoted, thus: "jo..hn.sm.ith"@yahoo.com ...

    As for the original question, preg_match could be made to work as far as I know, but a simple rejection of anything with two consecutive dots should really be all that's needed?
    /!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade! /!!!\ ereg() is deprecated --- don't use it!

    dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket

    Getting Help at All --- Collected Solutions to Common Problems --- Debugging 101 --- Unanswered Posts --- OMBE: Office Machines, Business Equipment

  3. #3
    phpMaster
    Join Date
    Jun 2005
    Location
    Europe
    Posts
    3,009
    Thanks.
    Gmail.com have this information:
    in john.smith@gmail.com the period is ignored,
    and is so the same as johnsmith@gmail.com

    In Stack Overflow I got the following solution to what I am trying to do:
    PHP Code:
    <?php

    $email 
    preg_replace('/\.(?=.*@)/'''$email);

    ?>
    It works exactly and fine.
    He calls it: "look ahead"
    Apache-2.4.28 (Win64) / PHP-7.1.10 / MySQL-5.7.19 / phpMyAdmin-4.7.4

  4. #4
    Settled 4 red convertible dalecosp's Avatar
    Join Date
    Jul 2002
    Location
    Accelerating Windows at 9.81 m/s....
    Posts
    8,522
    Quote Originally Posted by dalecosp View Post
    preg_match could be made to work
    Of course, I meant "preg_replace" ... MySQL croaked and refused to restart after an upgrade this AM ... #brain_busy

    Quote Originally Posted by halojoy View Post
    Thanks.
    Gmail.com have this
    Ah, well, that's different then ... any email service can, of course, impose its own more restrictive rules. Are you only checking @gmail.com addresses?

    PHP Code:
    <?php

    $email 
    preg_replace('/\.(?=.*@)/'''$email);

    ?>
    It works exactly and fine.
    He calls it: "look ahead"
    Yes, it's a "positive lookahead assertion".
    Last edited by dalecosp; 05-17-2017 at 06:26 PM.
    /!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade! /!!!\ ereg() is deprecated --- don't use it!

    dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket

    Getting Help at All --- Collected Solutions to Common Problems --- Debugging 101 --- Unanswered Posts --- OMBE: Office Machines, Business Equipment

  5. #5
    phpMaster
    Join Date
    Jun 2005
    Location
    Europe
    Posts
    3,009
    Quote Originally Posted by dalecosp View Post
    Of course, I meant "preg_replace" ... MySQL croaked and refused to restart after an upgrade this AM ... #brain_busy

    Ah, well, that's different then ... any email service can, of course, impose its own more restrictive rules. Are you only checking @gmail.com addresses?

    Yes, it's a "positive lookahead assertion".
    dalecosp, for my sign up application with activation, I of course expect all kinds of email.
    And I checked out at www.outlook.com.
    Now, there is different. They so treat john.smith@outlook.com as another email than johnsmith@outlook.com
    So, bottomline: I must give you right.
    Gmail have their rules, Outlook.com have other rules.

    I have decided to not remove periods in the sign up checking.
    Even if this opens up for duplicate account sign up with same Gmail.
    Apache-2.4.28 (Win64) / PHP-7.1.10 / MySQL-5.7.19 / phpMyAdmin-4.7.4

  6. #6
    Settled 4 red convertible dalecosp's Avatar
    Join Date
    Jul 2002
    Location
    Accelerating Windows at 9.81 m/s....
    Posts
    8,522
    Quote Originally Posted by halojoy View Post
    Gmail have their rules, Outlook.com have other rules.
    That's why we have standards ... in this case, RFC 5322. GMail is, for its own reasons, creating a more-restrictive policy than necessary.

    That's not unlike Google to do, as they've decided they're the 200 pound gorilla of the Internet and they can create their own standards on the chance that they will, indeed, become standards.

    I'm not so sure about this particular one though ...

    I have decided to not remove periods in the sign up checking.
    Even if this opens up for duplicate account sign up with same Gmail.
    You could, of course, have a conditional that checks the domain portion of the address ... if it matches "gmail.com" you could do your checking, otherwise, leave it alone.
    /!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade! /!!!\ ereg() is deprecated --- don't use it!

    dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket

    Getting Help at All --- Collected Solutions to Common Problems --- Debugging 101 --- Unanswered Posts --- OMBE: Office Machines, Business Equipment

  7. #7
    Senior Member Derokorian's Avatar
    Join Date
    Apr 2011
    Location
    Denver
    Posts
    2,261
    Quote Originally Posted by dalecosp View Post
    That's not unlike Google to do, as they've decided they're the 200 pound gorilla of the Internet and they can create their own standards on the chance that they will, indeed, become standards.
    But they aren't trying to make it standard, as only @gmail behaves this way. If you use gmail through school or an organization, dots matter.

    Note: If you use Gmail through work, school, or other organization (like yourdomain.com or yourschool.edu), adding dots to your username changes your email address. To change the dots in your username, contact your admin.
    So they aren't passing this behaviour off to people using the service under a different name, which is in itself kinda interesting.
    Sadly, nobody codes for anyone on this forum. People taste your dishes and tell you what is missing, but they don't cook for you. ~anoopmail
    I'd rather be a comma, then a full stop.
    User Authentication in PHP with MySQLi - Don't forget to mark threads resolved - MySQL(i) warning

  8. #8
    PHP Witch laserlight's Avatar
    Join Date
    Apr 2003
    Location
    Singapore
    Posts
    13,915
    There's another thing about gmail email addresses though: they permit aliasing by appending "+alias" to the mailbox name, e.g., one could sign up with example@gmail.com and example+somealias@gmail.com, hence the check should also check for this. But anyway, I agree with the decision to drop the issue: if a person wishes to sign up for multiple accounts, these may make it easier, but they can always sign up with entirely different email accounts and merely by checking the email addresses you will be none the wiser.
    Use Bazaar for your version control system
    Read the PHP Spellbook
    Learn How To Ask Questions The Smart Way

  9. #9
    Settled 4 red convertible dalecosp's Avatar
    Join Date
    Jul 2002
    Location
    Accelerating Windows at 9.81 m/s....
    Posts
    8,522
    Quote Originally Posted by Derokorian View Post
    But they aren't trying to make it standard, as only @gmail behaves this way. If you use gmail through school or an organization, dots matter.
    They *can't* "make" it a standard; what I'm trying to say is that they lead, others follow, and then there's a chance something they do becomes a standard. I'm talking in the abstract ... I (we) don't actually know their intent with their email local-part policy, or why they chose to do it that way.

    But they do have a HUGE amount of influence on the tech world and have personnel sitting in/on many standards committees/boards.

    So they aren't passing this behaviour off to people using the service under a different name, which is in itself kinda interesting.
    Well, they can't, because they can't guarantee that other services outside their control use the same rules for the local-part ... or am I missing something here?
    /!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade! /!!!\ ereg() is deprecated --- don't use it!

    dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket

    Getting Help at All --- Collected Solutions to Common Problems --- Debugging 101 --- Unanswered Posts --- OMBE: Office Machines, Business Equipment

  10. #10
    Senior Member Derokorian's Avatar
    Join Date
    Apr 2011
    Location
    Denver
    Posts
    2,261
    Quote Originally Posted by dalecosp View Post
    They *can't* "make" it a standard; what I'm trying to say is that they lead, others follow, and then there's a chance something they do becomes a standard. I'm talking in the abstract ... I (we) don't actually know their intent with their email local-part policy, or why they chose to do it that way.

    But they do have a HUGE amount of influence on the tech world and have personnel sitting in/on many standards committees/boards.



    Well, they can't, because they can't guarantee that other services outside their control use the same rules for the local-part ... or am I missing something here?
    Yeah, you're missing that you can use gmail, but not be @gmail. For example, many (maybe most?) colleges use gmail, but the students have @school.edu emails, but the service is gmail. What I was saying is that even though this service is gmail, the rules are not.

    Specifically derokorian@gmail.com and dero.korian@gmail.com are the same, but ryan@derokorian.com and ry.an@derokorian.com are not the same thing. However, I check both in gmail, I pay them for the @derokorian.com email hosting, but non-profits and schools are free. Hence the quote I included from their help site.

    AKA only @gmail follows this dot rule, even though there are hundreds (thousands?) of other domains hosted by gmail.

    https://gsuite.google.com/products/gmail/
    Sadly, nobody codes for anyone on this forum. People taste your dishes and tell you what is missing, but they don't cook for you. ~anoopmail
    I'd rather be a comma, then a full stop.
    User Authentication in PHP with MySQLi - Don't forget to mark threads resolved - MySQL(i) warning

  11. #11
    phpMaster
    Join Date
    Jun 2005
    Location
    Europe
    Posts
    3,009
    I found this solution.
    After this my Database will not allow same gmail with period and without period.

    I check if the submitted email is '@gmail'.
    If so I remove any period in the email before it is sent to database.
    Apache-2.4.28 (Win64) / PHP-7.1.10 / MySQL-5.7.19 / phpMyAdmin-4.7.4

  12. #12
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Contact Unit "Coping Mechanism"
    Posts
    22,534
    Don't forget that "@googlemail.com" is equivalent to "@gmail.com".
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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