Refactored method

- Getting character and restricted character is similar. However this
  change will turn all non-allowed characters to a whitespace.