软件编程
位置:首页>> 软件编程>> Android编程>> Android 校验email是否合法实现代码

Android 校验email是否合法实现代码

作者:lqh  发布时间:2021-06-02 05:18:24 

标签:Android,校验email

Android 校验email是否合法

这个其实跟JAVA中是一样的。例子:



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();
   }
 }

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com