js for the input refactored so the same regular expression didn't appear 2 times