public class Validator {
/**
* returns true if param is email
*
* @param email
* @return
*/
public boolean isEmailValid(CharSequence email) {
return android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches();
}
/**
* Returns true if string only contains alphabetical chars and whitespaces, ideal for
* validating names and last names
*
* @param name
* @return
*/
public boolean isAlpha(String name) {
return name.matches("[a-zA-Z|\\s]+");
}
/**
* If the string contains at least 7 digits, ideal for validating phone numbers
*
* @param phone
* @return
*/
public boolean isPhoneNumber(String phone) {
int count = 0;
for (int i = 0; i < phone.length(); i++) {
char c = phone.charAt(i);
if (Character.isDigit(c)) {
count++;
}
}
if (count >= 7) {
return true;
} else {
return false;
}
}
}
Helper class to help verify if strings are name, last names, phone number and email are valid.
#validator #name #lastname #phoneNumber #email #android
#cesarnog
#validator #name #lastname #phoneNumber #email #android
#cesarnog
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.