2008-11-01 17:32:06 -04:00
|
|
|
|
2009-12-14 21:50:53 -05:00
|
|
|
package com.fsck.k9;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2010-02-13 12:26:54 -05:00
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
2010-02-15 07:51:38 -05:00
|
|
|
import android.text.util.Rfc822Tokenizer;
|
2008-11-01 17:32:06 -04:00
|
|
|
import android.widget.AutoCompleteTextView.Validator;
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public class EmailAddressValidator implements Validator
|
|
|
|
{
|
2010-02-13 12:26:54 -05:00
|
|
|
// Source: http://www.regular-expressions.info/email.html
|
|
|
|
private static Pattern p = Pattern.compile(
|
|
|
|
"[a-z0-9!#$%&'*+/=?^_`{|}~-]+" +
|
|
|
|
"(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*" +
|
|
|
|
"@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+" +
|
|
|
|
"[a-z0-9](?:[a-z0-9-]*[a-z0-9])?");
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public CharSequence fixText(CharSequence invalidText)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public boolean isValid(CharSequence text)
|
2010-02-15 07:51:38 -05:00
|
|
|
{
|
|
|
|
return Rfc822Tokenizer.tokenize(text).length > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isValidAddressOnly(CharSequence text)
|
2009-11-24 19:40:29 -05:00
|
|
|
{
|
2010-02-13 12:26:54 -05:00
|
|
|
return p.matcher(text).matches();
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
}
|