Can someone help me with these regex validation with android Java :
Date : yyyy-mm-dd
Phone : (0999)-999-99-99
Email : [email protected]
-
1don't use regex to validate dates. Searching the site will give you the answers.Avinash Raj– Avinash Raj2015-04-22 13:15:21 +00:00Commented 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 acceptExplosion Pills– Explosion Pills2015-04-22 13:19:23 +00:00Commented Apr 22, 2015 at 13:19
-
ok.. i will use Edittext with datepicker and disable Edittext..Sanjay Kumar– Sanjay Kumar2015-04-22 13:20:34 +00:00Commented Apr 22, 2015 at 13:20
-
So no validation.. doesn't sound a very good idea..Sanjay Kumar– Sanjay Kumar2015-04-22 13:21:15 +00:00Commented Apr 22, 2015 at 13:21
Add a comment
|
1 Answer
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.