In Android, this form validation lib simplify and streamline the code to validate a form. It validates all type of EditText. It is used for all validation like
* Email
* Credit card Exp Year,Month, cvv
* Credit card Exp Year,Month, cvv
* Username
* Required Fields etc
* Required Fields etc
public class Formvalidation {
Context context;
EditText Username, Password, PhoneNumber;
static String emailPattern = "[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+";
public Formvalidation(Context context) {
this.context = context;
}
public static boolean isFirstName(EditText Et_Firstname) {
return Et_Firstname.getText().toString().isEmpty() ? false : true;
}
public static boolean isLastName(EditText Et_LastName) {
return Et_LastName.getText().toString().isEmpty() ? false : true;
}
public static boolean isUsername(EditText Et_Username) {
return Et_Username.getText().toString().isEmpty() ? false : true;
}
public static boolean isEmailValid(EditText Et_Username) {
return !Et_Username.getText().toString().matches(emailPattern) ? false : true;
}
public static boolean isConformPassword(EditText Et_ConformPassword) {
return Et_ConformPassword.getText().toString().isEmpty() ? false : true;
}
public static boolean isPassword(EditText Et_Password) {
return Et_Password.getText().toString().isEmpty() ? false : true;
}
public static boolean isPasswordMinLength(EditText Et_Password) {
return Et_Password.getText().toString().trim().length()<6 ? false : true;
}
public static boolean isConformPasswordMatch(EditText et_Password,
EditText et_ConformPassword) {
// TODO Auto-generated method stub
return !et_Password.getText().toString()
.equals(et_ConformPassword.getText().toString()) ? false : true;
}
public static boolean isPhoneNumber(EditText Et_Phonenumber) {
return Et_Phonenumber.getText().toString().isEmpty() ? false : true;
}
public static boolean isValidPhonenumber(EditText Et_valid_Phonenumber) {
return Et_valid_Phonenumber.getText().toString().length() != 10 ? false
: true;
}
public static boolean isAddress(EditText Et_Address) {
return Et_Address.getText().toString().isEmpty() ? false : true;
}
public static boolean isDob(EditText Et_Dob) {
return Et_Dob.getText().toString().isEmpty() ? false : true;
}
public static boolean isCardNumber(EditText Et_CardNumber) {
return Et_CardNumber.getText().toString().isEmpty() ? false : true;
}
public static boolean isCardHolder(EditText Et_CardHolder) {
return Et_CardHolder.getText().toString().isEmpty() ? false : true;
}
public static boolean isAmount(EditText Et_Amount) {
return Et_Amount.getText().toString().isEmpty() ? false : true;
}
public static boolean isExpireMonth(Spinner Expire_Montht) {
return Expire_Montht.getSelectedItem().toString().equals("Month") ? false : true;
}
public static boolean isExpireYear(Spinner Expire_Year) {
return Expire_Year.getSelectedItem().toString().equals("Year") ? false : true;
}
public static boolean isCvvr(EditText Et_Cvvt) {
return Et_Cvvt.getText().toString().isEmpty() ? false : true;
}
}
0 comments:
Post a Comment