Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4017796
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:54:18+00:00 2026-05-20T09:54:18+00:00

I’m running some functions to verify that the user-entered text in a form contains

  • 0

I’m running some functions to verify that the user-entered text in a form contains at least one number and letter. It doesn’t seem to be working. Since the two functions are nearly identical, I’ll just post one of them:

function hasALetter(textField){
    //returns true or false based on whether or not the text field has at least one letter inside it    
    console.log("Checking for letters...");

    var hasLetter = false;

    for(var i=0, checkLength=textField.length; i<checkLength; i++){
        var letter = textField.substr(i,1);
        console.log("letter = " + letter);
        if(isNan(letter) == false){
            hasLetter = false;
        }
    }
    if(hasLetter == true){
        return true;
    }
}

The log (“letter = ” + letter) never shows up in my console. I’m probably missing something silly, but it doesn’t seem to be completing the function.

For reference, here is how I’m calling the functions:

if(pwd.value.length > 9){

            var pwdLetter = hasALetter(pwd);
            var pwdNumber = hasADigit(pwd);

            if(pwdLetter==true){
                if(pwdNumber==true){

Yes, I’m aware that it’s very messy, but I’m still learning. I’m sure there’s more advanced/cleaner ways of doing this validation, but for the purposes of my schooling, I’m doing it like this for now.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T09:54:19+00:00Added an answer on May 20, 2026 at 9:54 am

    The easiest way to check if a string has a letter is the Regular Expression:

    function hasLetter(str){
      // check for characters between a and z
      // i flag makes it case insensitive
      return /[a-z]/i.test(str);
    }
    

    If you want to loop through the string and also want to use the isNaN function, this would do:

    function hasLetter(str){
    
      // loop through every character
      for(var i=0; i<str.length; i++){
    
        // check if the i-th character is not a number
        if(isNaN(str[i])){
    
          // if so, return true
          return true;
        }
      }
    
      // if the loop has finished and no letters have been found, return false
      return false;
    }
    

    But I would not recommend this method, because isNaN checks whether the first argument is a number or not. First of all, not all characters that aren’t numbers are letters. Secondly, the argument you pass in is a string (str[i] returns a character of type string, even if it is a digit)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.