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 7046709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:40:58+00:00 2026-05-28T02:40:58+00:00

I wonder what seems to be the problem in here. $(#city_field).bind({ keypress: function(event){ var

  • 0

I wonder what seems to be the problem in here.

$("#city_field").bind({
  keypress: function(event){
    var  regex = /^[a-zA-ZäöüÄÖÜ]/;
    if (regex.test($("#city_field").val())==true) {
    $('.r_validation').html('').css('background-color', '');
    } else {
        $('.validation').html("TEST").css('background-color', 'red');
    }
  }
});

Whenever I input letters it is valid, then when I input numbers the red validation notice appears. Everything is fine at this point, not until I entered numbers after letters. The following should be invalid, but in my current script it is seen as valid:

  • foo1212
  • foo,
  • foo, [with space after comma]

What I really want to validate is to ONLY accept letters and dash (-), nothing more other than that.

Thanks.

EDIT

For the record, the last comment of @Adam Rackis solved the issue, I ended up with this working code.

$(function(){
  $("#city_field").bind("keyup",
    function(event) {
      var regex = /^[a-zA-ZäöüÄÖÜ]+$/;
      if (regex.test($("#city_field").val())==true) {
        $('.validation').html('').css('background-color', '');
      } else {
          $('.validation').html("TEST").css('background-color', 'red');
      }
  });
});
  • 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-28T02:40:59+00:00Added an answer on May 28, 2026 at 2:40 am

    Your regex is matching only one character. You need to put that input over a Kleene closure, then put an end of string marker:

    /^[a-zA-ZäöüÄÖÜ]*$/;
    

    Or if you want to make sure there’s at least one character, you’d use the positive closure:

    /^[a-zA-ZäöüÄÖÜ]+$/;
    

    Which produces:

    var r = /^[a-zA-ZäöüÄÖÜ]+$/;
    
    console.log(r.test('Foo'));    //true
    console.log(r.test('Foo123')); //false
    console.log(r.test('foo,'));   //false 
    console.log(r.test('foo, '));  //false
    console.log(r.test('foo '));   //false
    

    DEMO

    ALSO, make sure you catch the keyup event, since keypress fires before the text in your textbox updates, so you’re always validating one character behind.


    So on your Regex:

    /^[a-zA-ZäöüÄÖÜ]/;
    

    When testing Foo123 the F would be consumed, and that’s it. Done.

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

Sidebar

Related Questions

The lackluster response here made me wonder this . I've been saddled with a
So here is the problem: Recently someone bought a new PC for server to
I have a strange problem which seems to have recently appeared. I used to
I have a problem with jQuery Quicksand and jQuery Lavalamp plugins. It seems they
Wonder what the difference between: static PROCESSWALK pProcess32First=(PROCESSWALK)GetProcAddress(hKernel,Process32First); ... pProcess32First(...); what is hKernel? Look
Wonder if anyone can help me understand how to sum up the column of
wonder why when I export my project to *.air and I install it on
wonder what's wrong <table id=tblDomainVersion> <tr> <td>Version</td> <td>No of sites</td> </tr> <tr> <td class=clsversion>1.25</td>
wonder whether someone can help me with the following one... I have a struct
I wonder if someone knows if there is a pre-made solution for this: I

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.