• Home
  • Troubleshoot
  • #Example
    • C
    • C++
    • Python
    • R-Programming
  • DSA
  • Quiz
  • Tutorial Videos
  • Home
  • Troubleshoot
  • #Example
    • C
    • C++
    • Python
    • R-Programming
  • DSA
  • Quiz
  • Tutorial Videos
  • #Deals
  • #News
  • #WiKi
  • #APPS
  • #Events
    • #WWDC
    • #I/O
    • #Ignite
  • #Let’s Talk

MyCodeTips mycodetips-newlogocopy1

  • Home
  • Troubleshoot
  • #Example
    • C
    • C++
    • Python
    • R-Programming
  • DSA
  • Quiz
  • Tutorial Videos
IOS, Swift

How to create Simple Registration form in SWIFT !

A form which we may use in multiple applications but each time that is Sign up or Registration form.

Below is the sample code of simple registration form

Below form contains the fields like

-First Name

-Last Name

-Email

-Password & Confirm Password

regform
Code

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var txtFName: UITextField!
@IBOutlet weak var txtLName: UITextField!
@IBOutlet weak var txtEmailID: UITextField!
@IBOutlet weak var txtPassword: UITextField!
@IBOutlet weak var txtConfirmPassword: UITextField!

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

@IBAction func btnRegistration(sender: AnyObject)
{
if(countElements(txtFName.text) == 0){
var alert : UIAlertView = UIAlertView(title: "Oops!", message: "Please enter your first name.",
delegate: nil, cancelButtonTitle: "OK")
alert.show()

}else if (countElements(txtLName.text) == 0){
var alert : UIAlertView = UIAlertView(title: "Oops!", message: "Please enter your last name.",
delegate: nil, cancelButtonTitle: "OK")
alert.show()

}else if (countElements(txtEmailID.text) == 0){
var alert : UIAlertView = UIAlertView(title: "Oops!", message: "Please enter your email id.",
delegate: nil, cancelButtonTitle: "OK")
alert.show()

}else if !isValidEmail(txtEmailID.text){
var alert : UIAlertView = UIAlertView(title: "Oops!", message: "Please enter your correct email id.",
delegate: nil, cancelButtonTitle: "OK")
alert.show()

}else if (countElements(txtPassword.text) == 0){
var alert : UIAlertView = UIAlertView(title: "Oops!", message: "Please enter your password.",
delegate: nil, cancelButtonTitle: "OK")
alert.show()

}else if (countElements(txtConfirmPassword.text) != countElements(txtPassword.text)){
var alert : UIAlertView = UIAlertView(title: "Oops!", message: "Confirmed password not matched please try again.",
delegate: nil, cancelButtonTitle: "OK")
alert.show()

}else{
var alert : UIAlertView = UIAlertView(title: "User Registration!", message: "Your Registration is successfully.",
delegate: nil, cancelButtonTitle: "OK")
alert.show()

}

}



func textFieldShouldReturn(textField: UITextField) -> Bool
{
if(textField.returnKeyType == UIReturnKeyType.Done)
{
textField .resignFirstResponder()
}
else
{
var txtFld : UITextField? = self.view.viewWithTag(textField.tag + 1) as? UITextField;
txtFld?.becomeFirstResponder()
}
return true
}

func isValidEmail(testStr:String) -> Bool {
let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"

var emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegEx)
let result = emailTest.evaluateWithObject(testStr)
return result
}

}

  • Click to share on Reddit (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • Click to share on Pocket (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
Written by Ranjan - 9865 Views
AUTHOR
Ranjan

I m Ranjan and Sharing my years of experience in Software Development. Love to code in Mobile apps (IOS, Android, Power Apps, Xamarin, Flutter), Machine Learning ( Beginner ), Dot Net, Databases ( SQL Server, MySql, SQLite), WordPress, Cloud Computing ( AWS, Azure, Google, MongoDB) and many more as required on project-specific. Besides this love to travel and cook.

Next Post
Previous Post

Subscribe for updates

Join 5,733 other subscribers

whiteboard

Whiteboard(PRO)

whiteboard

Whiteboard(lite)

alphabets

Kids Alphabet

techlynk

Techlynk

techbyte

Do2Day

techbyte

Techbyte

Latest Posts

  • Frameworks of IOS
    Frameworks of IOS – Part ( I )
  • NSFileManager or NSPathUtilities
    NSFileManager or NSPathUtilities in Objective-C
  • Passing data between view controllers in Objective-C
    Passing data between view controllers in Objective-C
  • structures-classes-enum
    Structures and Classes in swift !
  • control-system-swift
    Control Flow in Swift
  • swift-concurrency-await
    Concurrency in Swift
  • time-complexity-dsa
    The Term Time Complexity in DSA
  • objective-c-datatypes1
    Objective-C Data Types
  • Convert-jpeg-word
    Convert JPG to Word – Tips You Should Try!
  • objective-c-control-statements2
    Objective-C control statements and loops !

Quick Links

  • #about
  • #myapps
  • #contact
  • #privacy

Other Websites

  • #myQuestions
  • #myBhojanalaya
  • #gadgetFacts
  • #ifscCodesDB

Tag Cloud

Android Android Studio API APP Programming Apps ARC asp.net blogging Browser Config CSS DATABASE DFD error Features GUI HTML HTML5 IDE IIS installation Interview Questions IOS iPhone javascript Mac objective-c OneDrive OS Programming quicktips SDK SEO Settings SMO SQL swift swiftUI Teams Tips & Tricks Tools UI Web Wordpress Xcode

©mycodetips.com