텍스트에서 이모지 검사

피터·2022년 8월 5일
func hasCharacters() -> Bool {
	let pattern = "^[0-9a-zA-Z가-힣ㄱ-ㅎㅏ-ㅣ`~!@#$%^&*()\\-_=+\\[{\\]}\\\\|;:'\",<.>/?\\s]{0,}$"
	let regex = try? NSRegularExpression(pattern: pattern , options: .caseInsensitive)
	if let _ = regex?.firstMatch(in: self, options: [], range: NSRange(location: 0, length: self.count)) {
		return true
	}
	return false
}

자료 출처: 정규식으로 유효성 확인

profile
iOS 개발자입니다.

0개의 댓글