Swift 2 iOS9 文本大小写检查
Swift 2 iOS9 text case check
我正在尝试为以下示例找到解决方案。我已经创建了一个用户注册页面,我检查密码重置问题是否与实际密码不匹配(工作正常),但我想要做的是将输入的密码和密码重置问题转换为小写并检查没有比赛。我更愿意即时执行此操作,而不是将密码放入 var.
这样做的原因是为了确保无论特定字符的大小写如何,密码重置问题都与实际密码不同。
if (passWord.text) == (resetQuestion.text) {
let alertController = UIAlertController(title: "PASSWORD SECURITY ISSUE", message:
"password reset question must not match actual password!", preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default,handler: nil))
self.presentViewController(alertController, animated: true, completion: nil)
return
}
if String.lowercaseString.rangeOfString(passWord.text) == String.lowercaseString.rangeOfString(resetQuestion.text) {
let alertController = UIAlertController(title: "PASSWORD SECURITY ISSUE", message:
"password reset question must not match actual password!", preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default,handler: nil))
self.presentViewController(alertController, animated: true, completion: nil)
return
}
如有任何指点或帮助,我们将不胜感激。
您可以尝试一种 caseInsensitiveCompare 方法。像
if passWord.text.caseInsensitiveCompare(resetQuestion.text) == .OrderedSame {
let alertController = UIAlertController(title: "PASSWORD SECURITY ISSUE", message:
"password reset question must not match actual password!", preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default,handler: nil))
self.presentViewController(alertController, animated: true, completion: nil)
return
}
我正在尝试为以下示例找到解决方案。我已经创建了一个用户注册页面,我检查密码重置问题是否与实际密码不匹配(工作正常),但我想要做的是将输入的密码和密码重置问题转换为小写并检查没有比赛。我更愿意即时执行此操作,而不是将密码放入 var.
这样做的原因是为了确保无论特定字符的大小写如何,密码重置问题都与实际密码不同。
if (passWord.text) == (resetQuestion.text) {
let alertController = UIAlertController(title: "PASSWORD SECURITY ISSUE", message:
"password reset question must not match actual password!", preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default,handler: nil))
self.presentViewController(alertController, animated: true, completion: nil)
return
}
if String.lowercaseString.rangeOfString(passWord.text) == String.lowercaseString.rangeOfString(resetQuestion.text) {
let alertController = UIAlertController(title: "PASSWORD SECURITY ISSUE", message:
"password reset question must not match actual password!", preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default,handler: nil))
self.presentViewController(alertController, animated: true, completion: nil)
return
}
如有任何指点或帮助,我们将不胜感激。
您可以尝试一种 caseInsensitiveCompare 方法。像
if passWord.text.caseInsensitiveCompare(resetQuestion.text) == .OrderedSame {
let alertController = UIAlertController(title: "PASSWORD SECURITY ISSUE", message:
"password reset question must not match actual password!", preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default,handler: nil))
self.presentViewController(alertController, animated: true, completion: nil)
return
}