Android new/edit contacts, detect the email/email address format is legal

Source: Internet
Author: User

JB Version:
1.sim/usim Card Contact: You can directly use the editsimcontactactivity in the Usim_email_pattern, search and "Usim_email_pattern", the relevant code added to remove the comments can be


2. Phone Local Contact: Modify the code as follows
Contacteditorfragment.java (Packages\apps\contacts\src\com\android\contacts\editor)
A Introduction Package
Import Java.util.regex.Pattern;
B Add Variable
private static final String Usim_email_pattern = "0-9][a-z][a-z][_0-9][a-z][a-z][-_.*@0-9][a-z][a-z][-_.+";
In the C save function,
In the following statement:
if (!hasvalidstate () | | Mstatus! = status.editing) {
LOG.I (TAG, "[Save]!hasvalidstate ():" + (!hasvalidstate ())
+ " | Mstatus! = status.editing: "+ (mstatus! = status.editing)
+ ", Mstatus:" + mstatus);
return false;
}
Add later:
Email
for (int n = 0; n < mstate.size (); n++) {
Rawcontactdelta field = Mstate.get (n);
arraylist<valuesdelta> data = field.getmimeentries ("Vnd.android.cursor.item/email_v2");
if (data! = NULL)
for (int m = 0; m < data.size (); m++) {
String email = data.get (m). Getasstring ("Data1");
if (! Textutils.isempty (email)) {
if (! Pattern.matches (Usim_email_pattern, EMAIL)) {

Toast.maketext (Mcontext, R.string.email_invalid, Toast.length_short). Show ();
Getactivity (). Finish ();
return false;
}
}
}
}
KK version
1. Sim/usim Card Contact:
Simeditprocessor.java (Alps\packages\apps\contacts\src\com\mediatek\contacts\simservice)
Add Private Boolean memailinvalid = False first;
And then Modify
Private Boolean Isusimupdatevaluesinvalid ()
MTK Add
if (! Textutils.isempty (Mupdatemail)) {
if (! Pattern.matches (Usim_email_pattern, Mupdatemail)) {
Memailinvalid = true;
}
}
MTK Add End
LOGUTILS.I (TAG, "mnumberisnull:" + Mnumberisnull + ", Mnumberinvalid:" +
Mnumberinvalid + ", Mfixnumberinvalid:" + mfixnumberinvalid); Reference location

Re-Modify
Private Boolean Isinsertvaluesinvalid ()
if (! Textutils.isempty (Mupdateadditionalnumber)) {
if (! Pattern.matches (Sim_num_pattern, Phonenumberutilsex
. Extractclirportion (Mupdateadditionalnumber))) {
Mfixnumberinvalid = true;
}
}//Reference Position
MTK Add
if (! Textutils.isempty (Mupdatemail)) {
if (! Pattern.matches (Usim_email_pattern, Mupdatemail)) {
Memailinvalid = true;
}
}
MTK Add End

Last modified
Private Boolean Setsavefailtoasttext ()
}*/else if (memailinvalid) {
Msavefailtoaststrid = R.string.cannot_insert_error_format_email; Resources Please add yourself
Memailinvalid = false;
2. Phone Local Contact: Modify the code as follows
Contacteditorfragment.java (Packages\apps\contacts\src\com\android\contacts\editor)
A Introduction Package
Import Java.util.regex.Pattern;
B Add Variable
private static final String Usim_email_pattern = "0-9][a-z][a-z][_0-9][a-z][a-z][-_.*@0-9][a-z][a-z][-_.+";
In the C save function,
In the following statement:
if (!hasvalidstate () | | Mstatus! = status.editing) {
LOG.I (TAG, "[Save]!hasvalidstate ():" + (!hasvalidstate ())
+ " | Mstatus! = status.editing: "+ (mstatus! = status.editing)
+ ", Mstatus:" + mstatus);
return false;
}
Add later:
Email
for (int n = 0; n < mstate.size (); n++) {
Rawcontactdelta field = Mstate.get (n);
arraylist<valuesdelta> data = field.getmimeentries ("Vnd.android.cursor.item/email_v2");
if (data! = NULL)
for (int m = 0; m < data.size (); m++) {
String email = data.get (m). Getasstring ("Data1");
if (! Textutils.isempty (email)) {
if (! Pattern.matches (Usim_email_pattern, EMAIL)) {

Toast.maketext (Mcontext, R.string.email_invalid, Toast.length_short). Show ();
Getactivity (). Finish ();
return false;
}
}
}
}

Android new/edit contacts, detect the email/email address format is legal

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.