如何在UITextField中检测阿拉伯字符?

时间:2016-06-08 05:14:52

标签: xcode swift uitextfield

我是初学程序员iPhone。(swfit) 如何防止用户在文本字段中不使用阿拉伯语单词? 换句话说,我如何检测阿拉伯字符? 感谢

1 个答案:

答案 0 :(得分:0)

你可以正则表达式

let regex = try! NSRegularExpression(pattern: "[^A-Za-z0-9 \\-\\.\\:\\/]", options: [])

let firstMatch = regex.rangeOfFirstMatchInString(yourString, options: [], range: NSMakeRange(0, yourString.characters.count))

if firstMatch.location != NSNotFound {
    // Invalid character found
}