1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-14 21:45:14 -05:00
k-9/src/com/fsck/k9/EmailAddressValidator.java

33 lines
845 B
Java
Raw Normal View History

package com.fsck.k9;
2010-02-13 12:26:54 -05:00
import java.util.regex.Pattern;
import android.text.util.Rfc822Tokenizer;
import android.widget.AutoCompleteTextView.Validator;
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])?");
public CharSequence fixText(CharSequence invalidText)
{
return "";
}
public boolean isValid(CharSequence text)
{
return Rfc822Tokenizer.tokenize(text).length > 0;
}
public boolean isValidAddressOnly(CharSequence text)
{
2010-02-13 12:26:54 -05:00
return p.matcher(text).matches();
}
}