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

The Archive Base Latest Questions

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

In my current project, I have a textbox where the user will enter some

  • 0

In my current project, I have a textbox where the user will enter some numeric ID (like a product ID) — For example: 12345-123-1234567-12345.

I want to have a JavaScript in my aspx page that, when a user presses Ctrl+V to paste in text, will format that text irrespective of the text’s present format.

For example, if the text is in formatted like 12345---123-123456712345 then the function will format it to 12345-123-1234567-12345.

EDIT:

Tried your Suggetion but it’s not working. I tried like this way… below code sample

<asp:TextBox ID="TextBox1" runat="server"  Text="" ></asp:TextBox>
<br />
<br />

<script language="JavaScript" type="text/javascript">

    var tb = document.getElementById("TextBox1");
    tb.OnTextChanged = function () {

        this.value = this.value.replace("---", "-");
    }; 

</script>

It’s erroring out saying

Microsoft JScript runtime error: Unable to set value of the property
‘OnTextChanged’: object is null or undefined

  • 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-28T07:58:53+00:00Added an answer on May 28, 2026 at 7:58 am

    To update a textbox whenever its text is change, you can use the “onchange” event (just note that the change won’t happen until focus leaves the textbox)

    First, give your textbox a unique id—asp.net version 4 has features that allow you to give form elements id’s that won’t be “messed with”—then set the onchange event.

    var tb = document.getElementById("textBoxId");
    tb.onchange = function() {
       //I think you want:
       this.value = this.value.replace("---", "-");
    };
    

    EDIT

    You can catch the keyup event, and check to see if the user has just hit control-v. If so, you can modify the textbox’s current value. Just note that this will not work if the user pastes by right clicking.

    The best way to handle this is with the onchange event, which will work no matter how the textbox is changed.

       document.getElementById("tb").onkeyup = function (e) {
           var key = e.which || e.keyCode;
           if (e.which === 86 && e.ctrlKey)
               alert("you pasted " + this.value);
       }; 
    

    DEMO

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

Sidebar

Related Questions

I have a requirement on my current project (a Flex app which will be
I am hosting SpiderMonkey in a current project and would like to have template
I have some classes in my current project which have the wrong package declaration
I'm a .Net developer, but for my current project I have to create some
within my current project file I have a user control that has a storyboard
In my current project we have 5 different masterpages, there are some common elements
In my current project I have data about colors. Each color is either a
In my current project we have a large repository of content that was originally
I have a spec in my current project that requires us to advise the
I have a few classes in my current project where validation of Email/Website addresses

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.