com.dwivedi.androidformvalidation.validator.validations.IsEmail Maven / Gradle / Ivy
package com.dwivedi.androidformvalidation.validator.validations;
import android.content.Context;
/**
*
* @author Created by Ashish Dwivedi (see
* https://github.com/dwivedi/AndroidFormValidation-TheRightWay).
* Modified and incorporated to ioc-commons-android-impl by Jesús Lunar
* Pérez
*/
public class IsEmail extends BaseValidation {
private static final String EMAIL_PATTERN = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
private int errorMessageId;
private IsEmail(Context context, int errorMessageId) {
super(context);
this.errorMessageId = errorMessageId;
}
public static Validation build(Context context, int errorMessageId) {
return new IsEmail(context, errorMessageId);
}
@Override
public String getErrorMessage() {
return mContext.getString(this.errorMessageId);
}
@Override
public boolean isValid(String text) {
return isEmailValid(text);
}
public static boolean isEmailValid(String text) {
return text.matches(EMAIL_PATTERN);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy