반응형
iOS 15.5, Xcode 13.31, Swift 5, UIKit 환경에서 진행했습니다.
enum RegExModel {
static let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}"
static let idRegEx = "[A-Za-z0-9]{5,13}"
static let nickRegEx = "[가-힣A-Za-z0-9]{2,7}"
static let pwRegEx = "[A-Za-z0-9!_@$%^&+=]{8,20}"
static let phoneRegEx = "^[0-9+]{0,1}+[0-9]{5,16}$"
}
private func isValidEmail() -> Bool { // 이메일 체크
let tfEmailText = tfEmail.text
guard tfEmailText != nil else { return false }
let pred = NSPredicate(format: "SELF MATCHES %@", RegExModel.emailRegEx)
return pred.evaluate(with: tfEmailText)
}
반응형
'iOS > 코드조각' 카테고리의 다른 글
[iOS, Swift] ScrollView endEditing 사용하기 (0) | 2022.07.12 |
---|---|
[iOS, Swift] Alamofire responseDecodable 사용하기 (0) | 2022.07.12 |
[iOS, Swift] 코드로 Custom Color 지정하기(UIColor Extension) (0) | 2022.07.06 |
[iOS, Swift] CollectionView 초기 position 변경하기 (0) | 2022.07.06 |
[iOS, Swift] NotificationCenter Example (0) | 2022.07.06 |