邮箱判断正则表达式

来源:互联网 发布:知乎上传图片 编辑:程序博客网 时间:2024/05/06 14:25

           

            username = login_username.getText().toString();

            password = login_pwd.getText().toString();            
            if ("".equals(username) || "".equals(password)) {
                Toast.makeText(getApplicationContext(), "用户名或密码不能为空", Toast.LENGTH_SHORT).show();
            }else {    
                if (!EmailFormat(username)) {
                    Toast.makeText(this, "邮箱格式不正确", Toast.LENGTH_LONG).show();
                }else {
                    login(username,password);
                }

            }



    //邮箱判断正则表达式
    private boolean EmailFormat(String email) {
        Pattern pattern = Pattern.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
        Matcher mc = pattern.matcher(email);
        return mc.matches();
    }


原创粉丝点击