I am trying to play with regexes and test my own code in ruby. Using the example below, I would anticipate the final puts to return true, but it does not. The check_password method does, however, return "Your pw does not work because it is too short" Why doesn't the true/false check return true?
def err_message(reason)
puts "Your pw does not work because " + reason
end
def check_password(password)
if password.length<6
return err_message("it is too short")
elsif password.index(/[A-Z]/)==nil
return err_message("it does not contain a capital letter")
elsif password.index(/\d|[!,@,#,$,%,&,*,+,:,?]/)==nil
return err_message("it needs either a digit or special character")
elsif password.index(/([!,@,#,$,%,&,*,+,:,?\w])/)>0
return err_message("nope. !,@,#,$,%,&,*,+,:,? are the only special characters available")
else
return "Valid Password!"
end
end
puts check_password("aaaaa")=="Your pw does not work because it is too short"