Created
April 11, 2019 10:54
-
-
Save SergLam/aefe3bbbaa5499ed053de62780517b76 to your computer and use it in GitHub Desktop.
Validate only English regex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func validateQuestionLanguage(_ question: String) -> Bool { | |
if question.isEmpty { return true } | |
do { | |
let regex = try NSRegularExpression(pattern: "^[a-zA-Z0-9\"$@$!%*?&#^-_. +()_\\-=\\[\\]{};:\\|,<>\\/?]+$", options: .caseInsensitive) | |
return regex.matches(in: question, options: [], range: NSRange(location: 0, length: question.count)).count > 0 | |
} catch { | |
assert(false, "Invalid regex syntax") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment