• Home
  • DSA
  • Concept
  • Interview
  • Tips&Tricks
  • Tutorial Videos
  • Home
  • DSA
  • Concept
  • Interview
  • Tips&Tricks
  • Tutorial Videos
  • #News
  • #APPS
  • #Events
    • #WWDC
    • #I/O
    • #Ignite
  • #Let’s Talk
  • #Advertise

MyCodeTips mycodetips-newlogocopy1

  • Home
  • DSA
  • Concept
  • Interview
  • Tips&Tricks
  • Tutorial Videos
IOS, Swift

How to create Simple Registration form in SWIFT !

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
}

}

Liked it? Take a second to support Ranjan on Patreon!
become a patron button
  • 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)
  • More
  • Click to share on Pocket (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
Written by Ranjan - 10983 Views
AUTHOR
Ranjan

Namaste, My name is Ranjan, I am a graduate from NIT Rourkela. This website is basically about of what i learnt from my years of experience as a software engineer on software development specifically on mobile application development, design patterns/architectures, its changing scenarios, security, troubleshooting, tools, tips&tricks and many more.

Next Post
Previous Post

Support us

mycodetips mycodetips
Follow us @ LinkedIn 2850+

Subscribe for updates

Join 8,213 other subscribers

Latest Posts

  • YT-Featured-solidprinciples
    SOLID Principles of Software Design
  • IOS 16 Features
    Latest features in IOS 16
  • r-language
    How can R language be used for data analysis?
  • wordpress-coding-blog
    Guide To WordPress Coding Standards
  • YT-Featured-Algorithm
    What is Algorithm?
  • 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
whiteboard

Whiteboard(PRO)

whiteboard

Whiteboard(lite)

alphabets

Kids Alphabet

techlynk

Techlynk

techbyte

Do2Day

techbyte

Techbyte

  • #about
  • #myapps
  • #contact
  • #privacy
  • #Advertise
  • #Guestpost
  • #myQuestions

Android Android Studio API APP Programming Apps blogging CSS DATABASE dsa Features HTML HTML5 installation Interview Questions IOS iPhone javascript Mac objective-c OS Programming quicktips SDK SEO SQL swift Tips & Tricks Tools UI Web Wordpress Xcode

  • SOLID Principles of Software Design
  • Latest features in IOS 16
  • How can R language be used for data analysis?
  • Guide To WordPress Coding Standards
  • What is Algorithm?

©mycodetips.com