0

Can someone help me with these regex validation with android Java :
Date : yyyy-mm-dd
Phone : (0999)-999-99-99
Email : [email protected]

4
  • 1
    don't use regex to validate dates. Searching the site will give you the answers. Commented Apr 22, 2015 at 13:15
  • Don't use regex to validate phone numbers either (and probably not even emails) unless you have very specific rules for the emails/phones you will accept Commented Apr 22, 2015 at 13:19
  • ok.. i will use Edittext with datepicker and disable Edittext.. Commented Apr 22, 2015 at 13:20
  • So no validation.. doesn't sound a very good idea.. Commented Apr 22, 2015 at 13:21

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.