Android checks whether the entered email/email address format is valid when creating/editing a contact.
JB version:
1. SIM/USIM card contact: You can directly use USIM_EMAIL_PATTERN in EditSimContactActivity to search for "USIM_EMAIL_PATTERN" and remove the comments added to the relevant code.
2. Mobile phone local contact: Modify the Code as follows:
ContactEditorFragment. java (packages \ apps \ contacts \ src \ com \ android \ contacts \ editor)
A import 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;
}
Then add:
// Email
For (int n = 0; n <mState. size (); n ++ ){
RawContactDelta field = mState. get (n );
ArrayList 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)
First add private boolean mEmailInvalid = false;
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
Modify again
Private boolean isInsertValuesInvalid ()
If (! TextUtils. isEmpty (mUpdateAdditionalNumber )){
If (! Pattern. matches (SIM_NUM_PATTERN, PhoneNumberUtilsEx
. ExtractCLIRPortion (mUpdateAdditionalNumber ))){
MFixNumberInvalid = true;
}
} // Reference location
// 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; // Add resources by yourself
MEmailInvalid = false;
2. Mobile phone local contact: Modify the Code as follows:
ContactEditorFragment. java (packages \ apps \ contacts \ src \ com \ android \ contacts \ editor)
A import 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;
}
Then add:
// Email
For (int n = 0; n <mState. size (); n ++ ){
RawContactDelta field = mState. get (n );
ArrayList 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;
}
}
}
}