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

  • SEARCH
  • Home
  • 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 8645993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:41:26+00:00 2026-06-12T12:41:26+00:00

Trying to get a class change when entering any character other than lowercase letters

  • 0

Trying to get a class change when entering any character other than lowercase letters in a text box. However, and I am sure that there is some stupid little thing causing this, its is not showing console.log of “yo!”. Here is the javascript:

$(function(){
    $("input[name='name']").keyup(function(){
        var str = $(this).val();
        var badChars = new RegExp("[^a-z]");
        if (str.indexOf(badChars)!=-1){
            console.log("yo!");
            $(this).removeClass("good");
            $(this).addClass("error");
        }
    });
});

What am I messing up?

  • 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-06-12T12:41:27+00:00Added an answer on June 12, 2026 at 12:41 pm
    $(function() {
        // Don't need to create new RegExp object on each keyup event.
        // Just create it once:
        var badChars = new RegExp("[^a-z]");
    
        $("input[name='name']").keyup(function() {
            // Use RegExp.test() method to check 
            // is string matches the regular expression.
            if (badChars.test(this.value)) {
                console.log("yo!");
                $(this).removeClass("good")
                       .addClass("error");
            }
        });
    });
    

    RegExp.test() method

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

Sidebar

Related Questions

I'm trying to get letters in a word to change color to red when
I'm trying to get all options other than the selected one and with the
Hi I am trying to get RecursiveDirectoryIterator class using a extension on the FilterIterator
I'm new to MVC and Codeigniter and am trying to get a class working.
I'm using SharpPcap to capture packets. I'm trying to get Traffic Class value and
im trying to get my jquiz class to count for 2 IDs for each
I'm trying to get values from nsdata class and doesn't work. here is my
I am trying to get this working in Scala: class MyClass(some: Int, func: AnyRef*
I am trying to get all the images with class front and display their
I'm trying to get rounded corners to on of my css class with the

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.