mardi 14 avril 2020

javascript ,jquery to check if an input field is only letters and not numbers

I'm trying to put some logic into my js to check that a user can only input letters into an input field and not numbers. The two fields are for city and state. I know I should be using an if/else statement and possibly typeOf? Any help would be much appreciated! so then if numbers are present then I'd console.log and/or alert('no numbers or whatever'); I tried the first solution with only using html but that did not work for me and thanks for the first answer though!!!. The input fields are not inside of a form tag and when I wrap them in a form my js stops working. Is there a way to check it another way?

        $submitBtn.on('click', function () {
        let city = $cityBox.val().trim();
        let state = $stateBox.val().trim();  // trying to figure out how to do it on both of these 

        //variables. 


       //below are 2 function to run inside this submit btn click.
       // savedHistory(city, state); 
       // dailyWeather(city, state);      
    })


Aucun commentaire:

Enregistrer un commentaire