WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Apostrophes or Single Quote support in user registration email address (9 posts)

  1. mobot123
    Member
    Posted 3 years ago #

    For a user email field, if the email address contain apostrophes or single quote (example abc'cd@abc.com), then you will get error per below while submit the form.

    ERROR: The email address isn’t correct.

    This is due to formatting.php is_email() validation checking not allow the email address with single quote ' to pass through when do email address checking. I am using wordpress version 3.0.5

    After some digging, I manage to make it work, and to share the workaround.
    1. Go to your wordpress folder and open file \wordpress\wp-includes\formatting.php
    2. Search for is_email keyword, or faster way search for "function is_email" without the quote.
    3. Look at comment // LOCAL PART Test for invalid characters. Example of the code per below:

    // LOCAL PART
    	// Test for invalid characters
    	if ( !preg_match( '/^[a-zA-Z0-9!#$%&\'*+\/=?^_
    {|}~\.-]+$/', $local ) ) {
    return apply_filters( 'is_email', false, $email, 'local_invalid_chars' );
    }`

    4. Copy paste code below to replace above piece of code:

    // LOCAL PART
    	// Test for invalid characters
    	if ( preg_match( '/[!#$%&*+\/=?^
    {|}~]/', $local ) ) {
    return apply_filters( 'is_email', false, $email, 'local_invalid_chars' );
    }`

    5. Basically it change the way the regular expression work to check for invalid character. Save the file and it should be working fine with user email address with '.

    If any problem, please do help me to fix ya.. :)
    If the solution work, do let me know too.... I not done through intensive testing, so take your own risk.

  2. mobot123
    Member
    Posted 3 years ago #

    Recopy the example code here... as the backticks code make it appear weird.

    // LOCAL PART
    // Test for invalid characters
    if ( preg_match( '/[!#$%&*+\/=?^`{|}~]/', $local ) ) {
    return apply_filters( 'is_email', false, $email, 'local_invalid_chars' );
    }

  3. swinhoe
    Member
    Posted 3 years ago #

    This works great for me.

    Why cant we have this added to the core / or at least built as a plugin so its not overwritten on each upgrade ?

    Thanks mobot123 :)

  4. mobot123
    Member
    Posted 3 years ago #

    swinhoe,
    I have the same thought, wordpress.org team should be aware of this. Just they not fixing it. Anyway, glad to hear the solution work for you.

  5. swinhoe
    Member
    Posted 2 years ago #

    Im trying to write a plugin to fix this in the meantime -

    I have had a look about for an existing one, but without luck.

    Before I continue, have you built a Plugin on this subject before ?

    thanks

  6. berseck
    Member
    Posted 2 years ago #

    Wanna know a good reason for not doing that??

    Simple... the user won't be able to login using his email if you want to... because it will save with a escape on the database and you won't be ever able to check if that is valid or not...

    And for updates in future you shouldn't change the wordpress core files...

  7. swinhoe
    Member
    Posted 2 years ago #

    Thats why im writing it as a plugin...

    The email does not appear with the escape in the DB and is still useable - does this mean it should be ok so long as the core is not amended ?

  8. mobot123
    Member
    Posted 2 years ago #

    I never wrote a plugin before. It will be good if solution for this problem got solve in a plugin.

  9. swinhoe
    Member
    Posted 2 years ago #

    Good advice here - but I still cant get it to work as it should.

    http://wordpress.org/support/topic/writing-a-plugin-to-amend-the-core-possible?replies=7#post-2339585

    I opened a ticket in Trac to address this - im now weighing up if its worth writing the plugin before it gets ptched.. ?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags