Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- calendar
- addTextChangedListner
- cocoapod
- backgroundTint
- livedata
- prolificinteractive/material-calendarview
- PostgreSQL
- viewmodel
- editText
- DialogFragment
- 리눅스
- springboot
- RestAPI
- podinit
- Button
- android
- Dialog
Archives
- Today
- Total
코코딩딩
[안드로이드/android] 비밀번호,핸드폰번호 정규식 본문
핸드폰번호 정규식을 이용해 일치하면 동작하는 코드를 작성하고자 한다.
// 클래스 전역으로 정규식을 선언해준다.
private String phone_pattern = "^01([0|1|6|7|8|9])-?([0-9]{4})-?([0-9]{4})$";
// if문을 이용해 정규식과 일치하는지 확인한다.
if(Pattern.matches(phone_pattern,binding.newPhNumEt.getText().toString())){
// 패턴과일치(true) 동작코드
}else{
Toast.makeText(AccountActicity.this, "핸드폰 번호를 다시한번 확인해주세요", Toast.LENGTH_SHORT).show();
}
비밀번호 정규식을 이용해 숫자,영문,특수문자 조합으로 8~20자와 일치하면 동작하는 코드를 작성하고자 한다.
비밀번호와 다른 형태지만 같은 기능을 한다.
//정규식
Pattern pw_pattern = Pattern.compile("^(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[!@#$%^&*])[a-zA-Z0-9!@#$%^&*]{8,20}$");
//if문
String pw = binding.newPwEt.getText().toString();
Matcher matcher = pw_pattern.matcher(pw);
if(!matcher.matches()){
// 일치하지 않을 경우
}else {
//일치할경우
}
'일단기록 > 간단기록' 카테고리의 다른 글
[JAVA] 시간 계산 하기 (0) | 2022.05.20 |
---|---|
[안드로이드/android] activity 화면 전환 데이터 주고받기 (intent) (0) | 2022.05.19 |
[안드로이드/android] editText 위에 겹쳐진 버튼 (0) | 2022.05.18 |
[JAVA] 10초 마다 반복 실행하기 (0) | 2022.05.10 |
[자료구조] json 실수한것 (0) | 2022.05.09 |