Skip to content

Commit

Permalink
chore: handle white spaces in username validation
Browse files Browse the repository at this point in the history
  • Loading branch information
mumer92 committed Nov 14, 2023
1 parent cc70b4a commit a62c71e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class SignInViewModel: ObservableObject {

@MainActor
func login(username: String, password: String) async {
guard !validator.containsWhitespace(username) else {
guard validator.isValidUsername(username) else {
errorMessage = AuthLocalization.Error.invalidEmailAddressOrUsername
return
}
Expand Down
10 changes: 2 additions & 8 deletions Core/Core/View/Validator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,7 @@ public class Validator {
return password.count >= 2
}

public func containsWhitespace(_ string: String) -> Bool {
return string.containsWhitespace
}
}

fileprivate extension String {
var containsWhitespace : Bool {
return(rangeOfCharacter(from: .whitespacesAndNewlines) != nil)
public func isValidUsername(_ string: String) -> Bool {
return !string.trimmingCharacters(in: .whitespaces).isEmpty
}
}

0 comments on commit a62c71e

Please sign in to comment.