Validator
public struct Validator<Value> : Sendable
规则验证器,可扩展
-
创建可选句柄验证器,值为nil时自行处理
Declaration
Swift
public static func predicate( _ predicate: @escaping @Sendable (Value?) -> Bool ) -> Self
-
转换为AnyValidator,开启类型验证
Declaration
Swift
public var anyValidator: AnyValidator { get }
-
转换为不安全的AnyValidator,关闭类型验证
Declaration
Swift
public var unsafeAnyValidator: AnyValidator { get }
-
默认验证器,值为nil时返回false
Declaration
Swift
public init()
-
初始化包装验证器,转发调用
Declaration
Swift
public init<WrappedValue>( _ validator: Validator<WrappedValue> ) where WrappedValue? == Value
-
初始化句柄验证器,值为nil时返回false
Declaration
Swift
public init( _ predicate: @escaping @Sendable (Value) -> Bool )
-
执行验证并返回结果
Declaration
Swift
public func validate(_ value: Value?) -> Bool
-
Nil有效验证器,仅nil时返回true,兼容嵌套Optional
Declaration
Swift
public static var isNil: `Self` { get }
-
非Nil有效验证器,非nil时返回true,兼容嵌套Optional
Declaration
Swift
public static var isNotNil: `Self` { get }
-
固定有效验证器,始终返回true
Declaration
Swift
public static var isValid: `Self` { get }
-
固定无效验证器,始终返回false
Declaration
Swift
public static var isInvalid: `Self` { get }
-
KeyPath包装验证器
Declaration
Swift
public static func keyPath<T>( _ keyPath: @autoclosure @escaping @Sendable () -> KeyPath<Value, T>, _ validator: @autoclosure @escaping @Sendable () -> Validator<T> ) -> Self
-
KeyPath验证器
Declaration
Swift
public static func keyPath( _ keyPath: @autoclosure @escaping @Sendable () -> KeyPath<Value, Bool> ) -> Self
-
等于验证器
Declaration
Swift
public static func ==( lhs: Self, rhs: Self ) -> Self
-
不等于验证器
Declaration
Swift
public static func !=( lhs: Self, rhs: Self ) -> Self
-
非验证器
Declaration
Swift
public static prefix func !( validator: Self ) -> Self
-
与验证器
Declaration
Swift
public static func &&( lhs: Self, rhs: @autoclosure @escaping @Sendable () -> Self ) -> Self
-
或验证器
Declaration
Swift
public static func ||( lhs: Self, rhs: @autoclosure @escaping @Sendable () -> Self ) -> Self
-
空验证器
Declaration
Swift
public static var isEmpty: `Self` { get }
-
非空验证器
Declaration
Swift
public static var isNotEmpty: `Self` { get }
-
相等验证器
Declaration
Swift
public static func isEqual( _ equatableValue: @autoclosure @escaping @Sendable () -> Value ) -> Self
-
小于验证器
Declaration
Swift
public static func less( _ comparableValue: @autoclosure @escaping @Sendable () -> Value ) -> Self
-
小于等于验证器
Declaration
Swift
public static func lessOrEqual( _ comparableValue: @autoclosure @escaping @Sendable () -> Value ) -> Self
-
大于验证器
Declaration
Swift
public static func greater( _ comparableValue: @autoclosure @escaping @Sendable () -> Value ) -> Self
-
大于等于验证器
Declaration
Swift
public static func greaterOrEqual( _ comparableValue: @autoclosure @escaping @Sendable () -> Value ) -> Self
-
值区间验证器
Declaration
Swift
public static func between( min: @autoclosure @escaping @Sendable () -> Value, max: @autoclosure @escaping @Sendable () -> Value ) -> Self
-
包含验证器
Declaration
Swift
public static func contains<S: StringProtocol>( _ string: @autoclosure @escaping @Sendable () -> S, options: @autoclosure @escaping @Sendable () -> String.CompareOptions = [] ) -> Self
-
包含前缀验证器
Declaration
Swift
public static func hasPrefix<S: StringProtocol>( _ prefix: @autoclosure @escaping @Sendable () -> S ) -> Self
-
包含后缀验证器
Declaration
Swift
public static func hasSuffix<S: StringProtocol>( _ suffix: @autoclosure @escaping @Sendable () -> S ) -> Self
-
指定长度验证器
Declaration
Swift
public static func length( _ count: @autoclosure @escaping @Sendable () -> Int ) -> Self
-
长度区间验证器
Declaration
Swift
public static func length( min: @autoclosure @escaping @Sendable () -> Int = 0, max: @autoclosure @escaping @Sendable () -> Int ) -> Self
-
正则验证器
Declaration
Swift
public static func regex( _ rule: String ) -> Self
-
英文字母验证器
Declaration
Swift
public static var isLetter: `Self` { get }
-
字母和数字验证器,不含下划线
Declaration
Swift
public static var isWord: `Self` { get }
-
整数验证器
Declaration
Swift
public static var isInteger: `Self` { get }
-
数字验证器
Declaration
Swift
public static var isNumber: `Self` { get }
-
合法金额验证器,两位小数点
Declaration
Swift
public static var isMoney: `Self` { get }
-
中文验证器
Declaration
Swift
public static var isChinese: `Self` { get }
-
手机号验证器
Declaration
Swift
public static var isMobile: `Self` { get }
-
座机号验证器
Declaration
Swift
public static var isTelephone: `Self` { get }
-
邮政编码验证器
Declaration
Swift
public static var isPostcode: `Self` { get }
-
身份证验证器
Declaration
Swift
public static var isIdcard: `Self` { get }
-
邮箱验证器
Declaration
Swift
public static var isEmail: `Self` { get }
-
合法时间验证器,格式:yyyy-MM-dd HH:mm:ss
Declaration
Swift
public static var isDatetime: `Self` { get }
-
合法时间戳验证器,格式:1301234567
Declaration
Swift
public static var isTimestamp: `Self` { get }
-
坐标点字符串验证器,格式:latitude,longitude
Declaration
Swift
public static var isCoordinate: `Self` { get }
-
URL验证器
Declaration
Swift
public static var isUrl: `Self` { get }
-
HTML验证器
Declaration
Swift
public static var isHtml: `Self` { get }
-
IPv4验证器
正则示例:.regex(“^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$”)
Declaration
Swift
public static var isIPv4: `Self` { get }
-
IPv6验证器
Declaration
Swift
public static var isIPv6: `Self` { get }