Skip to content

Instantly share code, notes, and snippets.

@SergLam
Created April 11, 2019 10:54
Show Gist options
  • Save SergLam/aefe3bbbaa5499ed053de62780517b76 to your computer and use it in GitHub Desktop.
Save SergLam/aefe3bbbaa5499ed053de62780517b76 to your computer and use it in GitHub Desktop.
Validate only English regex
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