1var yourElement = document.getElementById("yourElement");
2yourElement.addEventListener("keydown", function (e) {
3 if (e.code === "Enter") { //checks whether the pressed key is "Enter"
4 validate(e);
5 }
6});
7
8function validate(e) {
9 var text = e.target.value;
10 //validation of the input...
11}