Skip to content

Instantly share code, notes, and snippets.

@Beepeach
Created August 5, 2021 02:22
let email: String = "beepeach@test.com"
let regularExpression: String = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}"
if let _ = email.range(of: regularExpression) {
print("Vaild Email Pattern")
} else {
print("InVaild Email Pattern") // InVaild Email Pattern
}
if let _ = email.range(of: regularExpression, options: .regularExpression) {
print("Vaild Email Pattern") // Vaild Email Pattern
} else {
print("InVaild Email Pattern")
}
let fakeEmail: String = "beepeach@test.com "
if let _ = fakeEmail.range(of: regularExpression, options: .regularExpression) {
print("Vaild Email Pattern") // Vaild Email Pattern
} else {
print("InVaild Email Pattern")
}
if let range = fakeEmail.range(of: regularExpression, options: .regularExpression),
range.lowerBound == fakeEmail.startIndex && range.upperBound == fakeEmail.endIndex {
print("Vaild Email Pattern")
} else {
print("InVaild Email Pattern") // InVaild Email Pattern
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment