gpt4 book ai didi

ios - 如何检查输入的电子邮件是电子邮件格式

转载 作者:搜寻专家 更新时间:2023-11-01 06:06:20 36 4
gpt4 key购买 nike

<分区>

如何检查输入的邮件是否格式正确。比如 somename@gmail.com 或任何。

这是我的代码。我试过了,但我的 if 语句出现错误

import UIKit

extension String {
func matchPattern(patStr:String)->Bool {
var isMatch:Bool = false
do {
let regex = try NSRegularExpression(pattern: patStr, options: [.CaseInsensitive])
let result = regex.firstMatchInString(self, options: NSMatchingOptions(rawValue: 0), range: NSMakeRange(0, characters.count))

if (result != nil)
{
isMatch = true
}
}
catch {
isMatch = false
}
return isMatch
}
}

class RegisterVC: UIViewController {



@IBOutlet weak var EmailField: UITextField!


@IBOutlet weak var LocationField: UITextField!

@IBOutlet weak var userNameField: UITextField!



@IBOutlet weak var passWordField: UITextField!



@IBOutlet weak var confirmPasswordField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
}
@IBAction func SignUpBtnPress(sender: AnyObject) {
let Email:NSString = EmailField.text!
let Location:NSString = LocationField.text!
let username:NSString = userNameField.text!
let password:NSString = passWordField.text!
let confirm_password:NSString = confirmPasswordField.text!

if (Email.matchPattern("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$")==true)
{
print("this is e-mail!")
}

else if ( Email.isEqualToString("") || Location.isEqualToString("") || username.isEqualToString("") || password.isEqualToString("") || confirm_password.isEqualToString("") ) {


let alertController = UIAlertController(title: "Alert", message: "All Field Are Mnditory.", preferredStyle: UIAlertControllerStyle.Alert)
let DestructiveAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default) { (result : UIAlertAction) -> Void in
print("Settings")
}

alertController.addAction(DestructiveAction)

self.presentViewController(alertController, animated: true, completion: nil)



} else if ( !password.isEqual(confirm_password) ) {

let alertController = UIAlertController(title: "Alert", message: "Password Din't Match.", preferredStyle: UIAlertControllerStyle.Alert)
let DestructiveAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default) { (result : UIAlertAction) -> Void in
print("Password Din't Match")
}

alertController.addAction(DestructiveAction)

self.presentViewController(alertController, animated: true, completion: nil)

}




print("login sucess")
}

我需要的是,如果任何用户开始绑定(bind)电子邮件 ID 的格式错误,我需要显示警报。

谢谢

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com