Created
October 7, 2020 10:56
-
-
Save christiancabarrocas/e6060b4061e17d80ff782c74157b4d4e to your computer and use it in GitHub Desktop.
Extension for Swift String
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
extension String { | |
func range(of string: String) -> NSRange { | |
return (self as NSString).range(of: string) | |
} | |
func initialLetter() -> String { | |
guard let letter = first else { return "" } | |
return String(letter) | |
} | |
static func empty() -> String { | |
return "" | |
} | |
func isValidEmail() -> Bool { | |
let regex = try! NSRegularExpression(pattern: "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}", options: .caseInsensitive) | |
return regex.firstMatch(in: self, options: [], range: NSRange(location: 0, length: count)) != nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment