Skip to content

Commit

Permalink
Added some basic input validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasWhittington committed Sep 14, 2024
1 parent 4285f07 commit 03f1b46
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ func main() {
fmt.Println("Enter number of tickets: ")
fmt.Scan(&userTickets)

if userTickets <= remainingTickets {
isValidName := len(firstName) >= 2 && len(lastName) >= 2
isValidEmail := strings.Contains(email, "@")
isValidTicketNumber := userTickets > 0 && userTickets <= remainingTickets

if isValidName && isValidEmail && isValidTicketNumber {
remainingTickets -= userTickets
bookings = append(bookings, firstName+" "+lastName)

Expand All @@ -54,7 +58,17 @@ func main() {
break //break and continue behave very similar to C#
}
} else {
fmt.Printf("We only have %v tickets remaining, so you can't book %v tickets", remainingTickets, userTickets)
if !isValidName {
fmt.Println("First name or last name is to short")
}

if !isValidEmail {
fmt.Println("Email didn't contain @")
}

if !isValidTicketNumber {
fmt.Println("number of tickets you entered is invalid")
}
}
}
}

0 comments on commit 03f1b46

Please sign in to comment.