简体   繁体   中英

Illegal character In email address after removing whitespaces

I am taking in an email address via EditText. I got an error saying the address contained whitespaces, no problem. I implemented address.removeAll("\\\\s" , ""); and now am getting the error

  • 04-16 09:37:43.009: W/System.err(1632): javax.mail.internet.AddressException: Illegal character in local name in string ``606#7f080011app:id/enterEmail}''

Here is my code for capturing the email and converting to a String.

      EditText e = (EditText) findViewById(R.id.enterEmail);

      String to = e.toString().replaceAll("\\s", "");

On the line where I use the address and get the error:

msg.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(to));

I have done some research trying to find if it is a parsing issue or what would be causing it but found nothing. Anybody know why I would be getting this error? Thanks in advance.

That's because you're converting your EditText to a String instead of getting its text and doing the replaceAll() on it.

Simply replace this:

String to = e.toString().replaceAll("\\s", "");

With this:

String to = e.getText().toString().replaceAll("\\s", "");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM