func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {

// 创造个除“123456789”外的字符串集合

let invalidCharacters = NSCharacterSet(charactersInString: "0123456789").invertedSet

if let range = string.rangeOfCharacterFromSet(invalidCharacters, options: nil, range:Range<String.Index>(start: string.startIndex, end: string.endIndex)) {

return false

}

return true

}

04-26 15:36