CoffeeCraft/Sources/CoffeeBeans/String+Validators.swift

19 lines
605 B
Swift

import Foundation
public extension String {
/// A Boolean value indicating whether the String is a valid email
var isValidEmail: Bool {
let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}"
let emailPred = NSPredicate(format:"SELF MATCHES %@", emailRegEx)
return emailPred.evaluate(with: self)
}
/// A Boolean value indicating whether the String has content other than whitespaces
var isPresent: Bool {
let trimmed = self.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
return !trimmed.isEmpty
}
}