본문 바로가기

iOS

[swift] 정규식

정규식 체크


func checkString(newText:String, filter:String = "[a-zA-Z0-9가-힣ㄱ-ㅎㅏ-ㅣ\\s]") -> Bool {

    let regex = try! NSRegularExpression(pattern: filter, options: [])

    let list = regex.matches(in:newText, options: [], range:NSRange.init(location: 0, length:newText.count))

    if(list.count != newText.count){

        return false

    }

    return true

}







'iOS' 카테고리의 다른 글

[ETC]유니코드 한글 변환  (0) 2019.03.13
[swift] UITextView글자수 제한(붙여넣기)  (0) 2017.12.01
[swift] Util(UIImageView)  (0) 2017.12.01
[swift] Util(UIImage)  (0) 2017.12.01
[swift] Util(String)  (0) 2017.12.01