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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:49:51+00:00 2026-05-28T06:49:51+00:00

i am validating an input box value so that it should contain only digit,.,-,/

  • 0

i am validating an input box value so that it should contain only digit,.,-,/ if at any time user type any thing accept allowed character, then only that character should get removed.

ex. if i typed initially 12/12/ then a, then only a should get removed from text box not whole string 12/12.

what i have tried so far.-

<input type="text" onkeyup="isValidDate(this);"/>
function isValidDate(f){ 
    var re =/^[\d\/\.-]+$/;
   if (!re.test(f.value)) { 
    alert("called");
    f.value = f.value.replace(/^[\d\/\.-]+$/g,"");
   }
 }

i am getting alert but un wanted value is not getting removed.

How i can do this using java script?

  • 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-28T06:49:52+00:00Added an answer on May 28, 2026 at 6:49 am

    You should be able to add a return in front of the function call.

    Then in the javascript return false if the character is unwanted.

    Here is what I would do below.

    <input type="text" onkeyup="return isValidDate(this);"/>
    function isValidDate(f){ 
        var re =/^[\d\/\.-]+$/;
       if (!re.test(f.value)) { 
        alert("called");
    //if you need to add a value instead that can also be done here
    return false;
       }
     }
    

    Here is code that I used to check that the key press was either a number or the decimal. It also alerts the user by setting the label field that is passed.

    <input id='txtUPT' name='UPT' type='text' style='width: 70px' onKeyPress="return NumbersOnly(event, 'lblStatusUPT')">
    <label id='lblStatusUPT' class='status'></label>
        function NumbersOnly(evt, label) {
            var status = document.getElementById(label);
            evt = (evt) ? evt : window.event;
            var charCode = (evt.which) ? evt.which : evt.keyCode;
            if (charCode == 46) {
                return true;
            }
            if (charCode < 48 || charCode > 57) {
                status.innerHTML = 'Numbers Only Please';
                return false;
            }
            status.innerHTML = '';
            return true;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When validating user inputs in an application that is to be run across multiple
I need to apply validation on input time intervals that are taken in as
In Model-View-Presenter pattern where should we write validations of user input.
I have a codeigniter form that contains two checkboxes: <input type=checkbox checked=checked id=box1 name=box1
I am validating a text box using javascript, now what happens is that if
I have input field <input type=text name=vehicle_make[] id=make1/> and i have help dropdown that
Is it enough to avoid javascript injection validating input data in such way: xssValidate
how do you prevent the entry of duplicate records in php mysql? validating input
I've got problems with setting focus to an input field after validating it. I've
Where do you put user input validation in a web form application? View: JavaScript

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.