0

Can someone help me with these regex validation with android Java :
Date : yyyy-mm-dd
Phone : (0999)-999-99-99
Email : abc@gmail.com

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Sanjay Kumar
  • 415
  • 4
  • 9
  • 19

1 Answers1

1

Since API Level 8 and above, Android has patterns for email, phone number e etc; that you can use. For example:

private boolean isValidEmail(CharSequence email) {
    if (!TextUtils.isEmpty(email)) {
        return Patterns.EMAIL_ADDRESS.matcher(email).matches();
    }
    return false;
}

private boolean isValidPhoneNumber(CharSequence phoneNumber) {
    if (!TextUtils.isEmpty(phoneNumber)) {
        return Patterns.PHONE.matcher(phoneNumber).matches();
    }
    return false;
}

For more details, see: http://developer.android.com/reference/android/util/Patterns.html

Hope this helps.