android edittext email,Android上EditText上的电子邮件地址验证
慕姐8265434
要執行電子郵件驗證,我們有很多方法,但是最簡單,最簡單的方法是兩種方法。1-使用EditText(....).addTextChangedListener它持續在EditText boxie email_id 中的每個輸入上觸發都是無效或有效的/**?* Email Validation ex:- tech@end.com*/final EditText emailValidate = (EditText)findViewById(R.id.textMessage);?final TextView textView = (TextView)findViewById(R.id.text);?String email = emailValidate.getText().toString().trim();String emailPattern = "[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+";emailValidate .addTextChangedListener(new TextWatcher() {?? ? public void afterTextChanged(Editable s) {?? ? if (email.matches(emailPattern) && s.length() > 0)? ? ? ? {?? ? ? ? ? ? Toast.makeText(getApplicationContext(),"valid email address",Toast.LENGTH_SHORT).show();? ? ? ? ? ? // or? ? ? ? ? ? textView.setText("valid email");? ? ? ? }? ? ? ? else? ? ? ? {? ? ? ? ? ? ?Toast.makeText(getApplicationContext(),"Invalid email address",Toast.LENGTH_SHORT).show();? ? ? ? ? ? //or? ? ? ? ? ? textView.setText("invalid email");? ? ? ? }? ? }?? ? public void beforeTextChanged(CharSequence s, int start, int count, int after) {? ? // other stuffs?? ? }?? ? public void onTextChanged(CharSequence s, int start, int before, int count) {? ? // other stuffs?? ? }?});?2- 最簡單的使用if-else條件的方法。使用getText()獲取EditText框字符串,然后與為電子郵件提供的模式進行比較。如果模式不匹配或無法匹配,請單擊按鈕的onTo消息。它不會在EditText框中每次輸入字符時觸發。簡單示例如下所示。final EditText emailValidate = (EditText)findViewById(R.id.textMessage);?final TextView textView = (TextView)findViewById(R.id.text);?String email = emailValidate.getText().toString().trim();String emailPattern = "[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+";// onClick of button perform this simplest code.if (email.matches(emailPattern)){Toast.makeText(getApplicationContext(),"valid email address",Toast.LENGTH_SHORT).show();}else?{Toast.makeText(getApplicationContext(),"Invalid email address", Toast.LENGTH_SHORT).show();}
總結
以上是生活随笔為你收集整理的android edittext email,Android上EditText上的电子邮件地址验证的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android 代码加view,Andr
- 下一篇: android map数据更新数据,An