dipen baks dipen baks - 2 months ago 29
Swift Question

Swift - password validation : Can anyone tell me what type of password this line wants?

let emailRegEx = "^(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$"
let passwordTest = NSPredicate(format:"SELF MATCHES %@",emailRegEx)
let result = passwordTest.evaluateWithObject(testStr)
return result


This is the code for my password validation function, can anyone tell me the meaning of it.

Answer
  • (?=.*?[0-9]) - At least One digit.

  • (?=.*?[#?!@$%^&*-]) - At least one special symbol from Specific set of allowed Special symbols(#?!@$%^&*-).

  • .{8,} - At least 8 characters.