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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:37:18+00:00 2026-05-26T23:37:18+00:00

I am trying to validate the input from the users with regular expressions here

  • 0

I am trying to validate the input from the users with regular expressions here is my codes

$('input[name="payment_rate"]').keyup(function(){
    var data = $(this).val();
    var regx = /^[0-9]+$/;

    console.log( data + ' patt:'+ data.match(regx));

    if( data.match(regx) ){
        $('.amt_err').fadeOut('slow');
    }
    else{
        $('.amt_err')
            .text('only Numeric Digits(0 to 9) allowed!')
            .css({'color':'#fff', 'background':'#990000', 'padding':'3px'});
    }
});

here is the html part:

<input type='text' class="txtbox" name='payment_rate' size='8'>&nbsp;<span class="amt_err"></span>

i want only digits but my code is only working the first time. I mean if I type any comma or alpha character, the error shows. But if I remove the same with backslash and again type the comma or something other than digits the error is not shown, I don’t know where the bug is in my code??

Please help me to find out the bug..

  • 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-26T23:37:18+00:00Added an answer on May 26, 2026 at 11:37 pm

    The first time the regexp matches (i.e. the content is ‘valid’), the error message element is hidden with .fadeOut(). On subsequent error, the message and css are modified, but the element is not made visible.

    The following works:

     $('input[name="payment_rate"]').keyup(function(){
        var data = $(this).val();
        var regx = /^[0-9]+$/;
    
        console.log( data + ' patt:'+ data.match(regx));
    
        if ( data === '' || data.match(regx) ){
            $('.amt_err').fadeOut('slow');
        }
        else {
            $('.amt_err')
                .text('only Numeric Digits(0 to 9) allowed!')
                .css({'color':'#fff', 'background':'#990000', 'padding':'3px'})
                .fadeIn('fast');
        }
    });
    

    In addition, the error message is hidden on zero-length string (i.e. empty). Not sure if that is required, but I’m guessing it is. See http://jsbin.com/uhelir/edit#javascript,html

    Also, have a look at http://www.zurb.com/playground/jquery-text-change-custom-event, a jQuery plugin that provides a ‘text-change’ event which is a nicer way to determine when a user has finished typing (and it won’t fire if the text hasn’t changed, reducing processing overhead).

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

Sidebar

Related Questions

I’m trying to validate input by using egrep and regex.Here is the line from
I am trying to validate user input. Here's the code: do{ NSLog(@Please select from
I'm trying to use 'errorPlacement' from jQuery Validation DOCS : $(#myform).validate({ errorPlacement: function(error, element)
I'm trying to use regex to validate input from the user, I'm wanting to
I am trying to validate user input from a form before submit but it
I'm trying to validate user input, which is just comma separated numbers. I'd like
I'm trying to validate a input field with the JQuery validation plugin. The numeric
I am trying to validate an input field when it loses focus and re-focus
I am trying to validate a text input when it loses focus. I would
I'm trying to practice writing better code, so I wanted to validate my input

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.