안드로이드 이메일 유효성 검사 코드
이런 식으로 제공 패턴을 사용하면 이메일이 맞는지 아닌지 확인 할 수 있다
- Patterns.EMAIL_ADDRESS
- Patterns.PHONE
- Patterns.WEB_URL
- Patterns.IP_ADDRESS
String email = "hydok@naver.com";
Pattern pattern = android.util.Patterns.EMAIL_ADDRESS;
if(pattern.matcher(email).matches()){
//이메일 맞음!
} else {
//이메일 아님!
}
안드로이드 이메일 유효성 검사 코드
login_emailok 클래스
이메일 인증 클래스이다
이메일 주소를 틀리게 치면
올바른 이메일 주소를 입력하세요가 뜬다
맞게 친다면
이메일 확인 중... 이 뜨고 다음 화면으로 넘어간다
public class login_emailok extends AppCompatActivity {
EditText editTextInputEmailAddress; // 이메일 입력란
Button nextButton; // 다음으로 버튼
String text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login_emailok);
editTextInputEmailAddress = (EditText) findViewById(R.id.editTextInputEmailAddress); // 이메일 입력란
nextButton = (Button) findViewById(R.id.nextButton); // 다음으로 버튼
// 다음으로 버튼 클릭 이벤트 등록
nextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 입력된 이메일 텍스트 가져오기
String email = editTextInputEmailAddress.getText().toString().trim();
// 이메일 유효성 검사
if (TextUtils.isEmpty(email) || !Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
// 이메일이 유효하지 않은 경우 에러 메시지 표시
editTextInputEmailAddress.setError("올바른 이메일 주소를 입력하세요");
return;
}
// 사용자에게 이메일 확인 중임을 알리는 토스트 메시지 표시
Toast.makeText(login_emailok.this, "이메일 확인 중...", Toast.LENGTH_SHORT).show();
// 이메일 확인이나 다음 액티비티로 이동
text = email;
Intent intent = new Intent(login_emailok.this, RegisterActivity.class);
intent.putExtra("VerifiedEmail", text);
startActivity(intent);
}
});
}
}
login_emailok.XML
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".login_emailok">\
<TextView
android:id="@+id/textView15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="120dp"
android:layout_marginTop="32dp"
android:text="이메일 인증"
android:textSize="34sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="100dp"
android:layout_marginTop="10dp"
android:text="가입하기전 이메일을 인증해주세요!"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView15" />
<EditText
android:id="@+id/editTextInputEmailAddress"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="130dp"
android:ems="10"
android:hint="이메일을 입력해주세요"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/nextButton"
android:layout_width="match_parent"
android:layout_height="47dp"
android:layout_marginStart="30dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="30dp"
android:text="다음으로"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editTextInputEmailAddress" />
</androidx.constraintlayout.widget.ConstraintLayout>
'Android' 카테고리의 다른 글
[Android] 안드로이드 네이밍/변수명 규칙 정하기 (0) | 2023.12.27 |
---|---|
[Android] EditeText password 숨기기 (0) | 2023.12.27 |
Android/활용안드로이드 - 로그인, 회원가입 간단 구현하기 (mysql, php 이용) (1) | 2023.12.08 |
안드로이드 이용 약관 동의 후 다음 화면 구현하기 (0) | 2023.12.08 |
D/NetworkSecurityConfig: No Network Security Config specified, using platform default HTTP 통신 오류 (0) | 2023.11.07 |