优雅的字符串判断拓展
优雅的实现通过一个外部方法判断多个输入字符串是否符合设定规则.
代码低耦合,拓展方便,使用方便.
实现手机号正则验证,以及邮箱账号正则验证.
将EWUserVerifyService文件拖入项目,调用时:
if let phone = phoneTextField.text,
let sms = smsTextField.text,
let password = passwordTextField.text,
let passwordSure = passwordSureTextField.text
{
///进行判断
let (isVerify, message) = UserVerifyService.verifyInput(phone: phone, code: sms, password: password, passwordSure: passwordSure)
///如果failed
if !isVerify {
///message:失败原因
if let message = message {
EWToast.showCenterWithText(text: message, duration: 1)
}
return
}
}
EWToast.showCenterWithText(text: "全部填写正确", duration: 1)