input functionality

changed code so that input string is overwritten in case of invalid
input instead on concatenating invalid input with a new valid input