本篇文章為大家展示了Android開發(fā)中如何實現(xiàn)校驗輸入的email是否合法,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。
Android 校驗email是否合法
String regEx = "^(([\\w-]+\\.)+[\\w-]+|([a-zA-Z]{1}|[\\w-]{2,}))@" +"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?" +"[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\." +"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?" +"[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|" +"([a-zA-Z]+[\\w-]+\\.)+[a-zA-Z]{2,4})$"; public void btnValidateEmailAddress(View v) { strEmailAddress = editTextEmail.getText().toString().trim(); Matcher matcherObj = Pattern.compile(regEx).matcher(strEmailAddress); if (matcherObj.matches()) { Toast.makeText(v.getContext(), strEmailAddress+" is valid", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(v.getContext(), strEmailAddress+" is InValid", Toast.LENGTH_SHORT).show(); } }