Results 1 to 3 of 3

Thread: Replace First Character in text box

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2002
    Location
    Hampton Beach
    Posts
    513

    Replace First Character in text box

    I have a text box and I want to have a fucntion that if the first character is T and the next character is a number then replace the T with a space and then trim the space...

    Ex: Text box= T1455

    Result: (no space)1455

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Replace First Character in text box

    Use RegEx to do your replacing.
    You can use [T][0-9] as your regex string, and if a match occurs, you do the replace the T.

    Something like

    if stringname.match("[T][0-9]")
    {
    //remove first letter
    }

  3. #3
    Fanatic Member Psyrus's Avatar
    Join Date
    Jul 2000
    Location
    NJ
    Posts
    602

    Re: Replace First Character in text box

    This should work:

    HTML Code:
    <html>
    <head>
    <title>String Fun</title>
    <script type = "text/javascript">
       function trimString(s){
          var len = s.length;
          if(s.match(/^(T|t){1}\d+$/)){
             frmMain.txtString.value = s.substring(1,len);
          }
       }
    </script>
    </head>
    <body>
    <form ID = "frmMain">
    <input type = "text" ID = "txtString" value = "" />
    <input type = "button" value = "Trim" onclick = "trimString(txtString.value);" />
    </form>
    </body>
    </html>
    Chris

    VB 6.0 Calendar App Video Gamers Group
    Don't forget to rate people if they helped you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width