Form Validation (JavaScript) | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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 Respostas
24th Feb 2022, 11:23 AM
furqan elahie
furqan elahie - avatar
+ 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