How can I verify a user enters email address in a EditTextPreference
for android setting ?
How to verify email input in android settings
779 views Asked by S.L. At
3
There are 3 answers
0
On
You must read it from SharedPreference
like this.
String email = PreferenceManager.getDefaultSharedPreferences(context).getString("your_pref_name","default_value")
if(!TextUtils.isEmpty(email)) {
//Perform operation on Email
} else {
//Show error
}
Listening to Preference Changes
If you want to listen to Preference changes, you must register a OnPreferenceChangeListener
on your Preference
and handle the inputs inside onPreferenceChange()
.
0
On
Import org.apache.commons.validator.routines.EmailValidator as one of your dependencies then use this method EmailValidator.getInstance().isValid("editText_email")
.
It does the necessary RegEx checks to validate if the email is valid or not.
By the way, You can use
inputType
inEditText
to validate the input as email by the system!You can use the default utility to validate!