单独校验
oldpwdTF.rx.text.orEmpty
.map { $0.count >5 } // 输入内容必须大于5位
.share(replay: 1)
.subscribe(onNext: {[weak self] (bool) in
self?.changePasswordButton.isEnabled = bool // 修改按钮是否可以点击
self?.changePasswordButton.backgroundColor = bool == true ? HWMainBarColor() : HWLineColor()
}, onError: { (error) in
}, onCompleted: nil, onDisposed: nil)
.disposed(by: disposeBag)
联合校验
/// 检验旧密码
let oldpwdValid = oldpwdTF.rx.text.orEmpty
.map { $0.count >5 } // 输入内容必须大于5位
.share(replay: 1)
/// 检验新密码
let newpwdValid = newpwdTF.rx.text.orEmpty
.map { $0.count > 5 && $0.count < 21 } // 输入内容必须大于5位 小于20
.share(replay: 1)
/// 检验确认密码
let confirmpwdValid = confirmpwdTF.rx.text.orEmpty
.map { $0.count > 5 && $0.count < 21} // 输入内容必须大于5位 小于20
.share(replay: 1)
/// 组合检验
Observable
.combineLatest(oldpwdValid, newpwdValid, confirmpwdValid) {$0&&$1&&$2}
.share(replay: 1)
.subscribe(onNext: {[weak self] (bool) in
self?.changePasswordButton.isEnabled = bool // 修改按钮是否可以点击
self?.changePasswordButton.backgroundColor = bool == true ? HWMainBarColor() : HWLineColor()
}, onError: { (error) in
}, onCompleted: nil, onDisposed: nil)
.disposed(by: disposeBag)
网友评论