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

Vadim Kotov
- 8,084
- 8
- 48
- 62

Sanjay Kumar
- 415
- 4
- 9
- 19
-
1don't use regex to validate dates. Searching the site will give you the answers. – Avinash Raj Apr 22 '15 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 – Explosion Pills Apr 22 '15 at 13:19
-
ok.. i will use Edittext with datepicker and disable Edittext.. – Sanjay Kumar Apr 22 '15 at 13:20
-
So no validation.. doesn't sound a very good idea.. – Sanjay Kumar Apr 22 '15 at 13:21
1 Answers
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.

Marcello Galhardo
- 740
- 6
- 14