Fixed JavaScript functions (regex and error messages)