Recap - Validation Function
Part of the Fundamentals section of Coddy's Swift journey — lesson 56 of 86.
Challenge
EasyWrite a function isValidPassword that takes password and minLength and returns whether the password meets the validation criteria.
A password is valid if it satisfies all of the following conditions:
Conditions:
- The password length must be at least
minLengthcharacters - The password length must not exceed 20 characters
- The password must not be equal to
"password"(case-sensitive)
Parameters:
password(String): The password to validateminLength(Int): The minimum required length
Returns: true if all conditions are met, false otherwise (Bool)
For example, if password is "Swift123" and minLength is 6, the function returns true because the password is 8 characters (at least 6), not more than 20, and not equal to "password".
Try it yourself
func isValidPassword(password: String, minLength: Int) -> Bool {
// Write code here
}
All lessons in Fundamentals
4Operators Part 1
Arithmetic OperatorsModulo OperatorCompound AssignmentRecap - Simple MathComparison Operators7Basic IO
Print FunctionString InterpolationReadLine InputType ConversionRecap - Till 120Recap - True or False10Functions
Declare A FunctionParameters And ArgumentsReturn ValuesArgument LabelsRecap - Sigma FunctionRecap - Validation FunctionDefault Values13Iterating Over Sequences
Iterating Over ElementsThe Enumerated MethodIterating Over Strings P1Iterating Over Strings P22Variables
Let vs VarType AnnotationsNumbersStringBooleanNaming ConventionsRecap - Initialize Variables5Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Ternary Operator8Bill Split Calculator
Welcome MessageGetting Input3Optionals
What Are OptionalsUnwrapping With If LetGuard LetNil Coalescing OperatorRecap - Safe Unwrapping9Loops
For-In LoopWhile LoopRepeat-While LoopBreakContinueRecap - FactorialRanges In LoopsNested LoopRecap - Dynamic Input