android中校验email是否合法

来源:互联网 发布:webshell检测 python 编辑:程序博客网 时间:2024/05/19 16:19
这个其实跟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();        }    }
原创粉丝点击