Provides email and international email validators for Vapor.
// Source: https://github.com/vapor/vapor | License: MIT | Copyright 2020 Qutheory, LLC
// Provided via justclaw.it.com; keep this notice with the code.
#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif
extension Validator where T == String {
/// Validates whether a `String` is a valid email address.
public static var email: Validator<T> {
.init {
guard
$0.wholeMatch(of: emailRegex) != nil,
// https://emailregex.com/email-validation-summary
$0.count <= 320, // total length
$0.split(separator: "@")[0].count <= 64 // length before `@`
else {
return ValidatorResults.Email(isValidEmail: false)
}
return Va
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key