+ 1

Form Validation (JavaScript)

I want to explicitly check that a user doesn’t input numbers in a name field... I ran this code to just test that it works on the console but it doesn’t. If I input numbers it the name field, the statement still fires... let fName = document.getElementById(“fName”) fName = addEventListener(“change”, () => { If (fName !== typeof Text) { console.log(“enter alphabets only”); } });

22nd Feb 2022, 11:58 PM
Blessing Ene Anyebe
Blessing Ene Anyebe - avatar
6 Respuestas
24th Feb 2022, 11:23 AM
furqan elahie
+ 2
This page has an example using RegEx, hope it helps https://www.fwait.com/how-to-check-if-string-contains-numbers-in-javascript/
23rd Feb 2022, 3:21 AM
Ipang
+ 1
What should happen when they type "George Edison the 5th" as name?
23rd Feb 2022, 1:35 AM
Ipang
+ 1
Ipang It should throw an error. “George Edison” alone should suffice.
23rd Feb 2022, 1:43 AM
Blessing Ene Anyebe
Blessing Ene Anyebe - avatar
+ 1
Ipang Thank you very much 🙏🏾
23rd Feb 2022, 3:22 AM
Blessing Ene Anyebe
Blessing Ene Anyebe - avatar
+ 1
Furqan_Elahie [Imaziue Coders] You rock! Thank you
24th Feb 2022, 3:41 PM
Blessing Ene Anyebe
Blessing Ene Anyebe - avatar