Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @IBOutlet weak var userNameTextField: UITextField!
- @IBOutlet weak var userPhoneTextField: UITextField!;
- @IBOutlet weak var userPasswordTextField: UITextField!;
- @IBOutlet weak var userConfirmPasswordTextField: UITextField!;
- @IBOutlet weak var userPlugTextField: UITextField!;
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view.
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- @IBAction func RegisterButtonTapped(_ sender: Any) {
- let userName = userNameTextField.text;
- let userPhone = userPhoneTextField.text;
- let userPassword = userPasswordTextField.text;
- let userConfirmPassword = userConfirmPasswordTextField.text;
- let userPlug = userPlugTextField.text;
- // Check for empty fields
- if(userName!.isEmpty || userPhone!.isEmpty || userPassword!.isEmpty || userConfirmPassword!.isEmpty || userPlug!.isEmpty)
- {
- // Display alert mmessage
- displayMyAlertMessage(userMessage: "All fields are required")
- return;
- }
- // check if passwords match
- if(userPassword != userConfirmPassword)
- {
- // Display an alert message
- displayMyAlertMessage(userMessage: "Passwords do not match")
- return;
- }
- // Store data
- UserDefaults.standard.set(userName, forKey: "userName")
- UserDefaults.standard.set(userName, forKey: "userPhone")
- UserDefaults.standard.set(userName, forKey: "userPassword")
- UserDefaults.standard.set(userName, forKey: "userPlug")
- UserDefaults.standard.synchronize();
- // Display alert message with confirmation
- _ = UIAlertController(title:"Alert", message:"Registration is successful. Thank you!", preferredStyle: UIAlertControllerStyle.alert);
- _ = UIAlertAction(title:"Ok", style: UIAlertActionStyle.default){ action in
- self.dismiss(animated: true, completion:nil)
- }
- myAlert.addAction(okAction);
- self.present(myAlert, animated:true, completion:nil)
- }
- func displayMyAlertMessage(userMessage:String)
- {
- let myAlert = UIAlertController(title:"Alert", message:userMessage, preferredStyle: UIAlertControllerStyle.alert);
- let okAction = UIAlertAction(title:"Ok", style: UIAlertActionStyle.default, handler:nil);
- myAlert.addAction(okAction);
- self.present(myAlert, animated:true, completion:nil);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement