为了账号安全,请及时绑定邮箱和手机立即绑定

检查电子邮件是否存在 sqlite 后将新用户插入数据库的问题

检查电子邮件是否存在 sqlite 后将新用户插入数据库的问题

慕标5832272 2021-10-27 16:53:57
我试图防止将用户双重插入到数据库中,并且每次收到消息时都检查电子邮件:my email already exists谢谢回答。检查是否userEmail已经存在:DataBaseHelper类:public boolean checkIfExists(String userEmail){    db = this.getReadableDatabase();    String query = "select "+ COL_EMAIL + " from " +TABLE_NAME;    Cursor cursor = db.rawQuery(query, null);    String existEmail;   if (cursor.moveToFirst()) {        do {            existEmail = cursor.getString(0);            if (existEmail.equals(userEmail)) {                return true;            }        } while (cursor.moveToNext());    }    return false;}验证电子邮件,检查电子邮件是否已经存在:Registration类:private boolean validateEmail() {    String emailInput = textInputEmail.getEditText().getText().toString().trim();    if (myDb.checkIfExists(emailInput)) {        textInputEmail.setError("Email already exist");        return false;    } else if (emailInput.isEmpty()) {        textInputEmail.setError("Field can't be empty");        return false;    } else if (!Patterns.EMAIL_ADDRESS.matcher(emailInput).matches()) {        textInputEmail.setError("Please enter a valid email address");        return false;    } else {        textInputEmail.setError(null);        return true;    }}
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 138 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信