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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:17:13+00:00 2026-06-17T15:17:13+00:00

Hi I have a Javascript code of Key press where I want to put

  • 0

Hi I have a Javascript code of Key press where I want to put “.” and numbers on the text box. I am able to put numbers but not “.”. I have the Javascript and HTMl and also Fiddle link. Can anyone help me with that?

<script>
    var aa_zChar = new Array(' ');
    var aa_maxphonelength = 8;
    var aa_phonevalue1;
    var aa_phonevalue2;
    var aa_cursorposition;
    function aa_ParseForNumber1(object){
      aa_phonevalue1 = aa_ParseChar(object.value, aa_zChar);
    }
    function a_ParseForNumber2(object){
      aa_phonevalue2 = aa_ParseChar(object.value, aa_zChar);
    }
    function aa_up(object,e) { 
      if(e){ 
        e = e 
      } else {
        e = window.event 
      } 
      if(e.which){ 
        var keycode = e.which 
      } else {
        var keycode = e.keyCode 
      }
      aa_ParseForNumber1(object)

        aa_ValidatePhone(object)

    }
    function aa_down(object,e) { 
      if(e){ 
        e = e 
      } else {
        e = window.event 
      } 
      if(e.which){ 
        var keycode = e.which 
      } else {
        var keycode = e.keyCode 
      }
      aa_ParseForNumber2(object)
    } 

    function aa_ValidatePhone(object){
      var p = aa_phonevalue1
      p = p.replace(/[^\d]*/gi,"") 
        object.value=p


    }

    function aa_ParseChar(sStr, sChar)
    {
      if (sChar.length == null) 
      {
        aa_zChar = new Array(sChar);
      }
        else aa_zChar = sChar;
      for (i=0; i<aa_zChar.length; i++)
      {
        sNewStr = "";
        var iStart = 0;
        var iEnd = sStr.indexOf(sChar[i]);
        while (iEnd != -1)
        {
          sNewStr += sStr.substring(iStart, iEnd);
          iStart = iEnd + 1;
          iEnd = sStr.indexOf(sChar[i], iStart);
        }
        sNewStr += sStr.substring(sStr.lastIndexOf(sChar[i]) + 1, sStr.length);
        sStr = sNewStr;
      }
      return sNewStr;
    }
    </script>

HTML

<input name="name" type="text" maxlength="100" id="name" value="" onKeyDown="aa_down(this,event);" onKeyUp="aa_up(this,event);" />

http://jsfiddle.net/4emDC/2/

  • 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-06-17T15:17:15+00:00Added an answer on June 17, 2026 at 3:17 pm

    Almost there. You just need to change the regex so that it accepts . alongwith numbers.
    One of the correct regular expressions would be /[^\d.]/gi

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

Sidebar

Related Questions

I have javascript code embedded inside a html template file. When I load this
i have this javascript code to which i want to add the jquery fade-in
I have this code: HTML <input type=text data-value=1 data-type=input-records placeholder=Value pattern=\d{1,4}$ /> CSS input[type=text]:invalid
I have the following code to test the menu button : <script type=text/javascript cahrset=utf-8>
Here is my code: <html> <head> <title>My Game Title Goes Here!</title> <script type=text/javascript> function
I have javascript code some thing like this -- var count=3; var pl=new Array(count);
I have JavaScript code which copies the value of input file and paste it
I have the JavaScript code to fadein.fadeout the menu, when ever user hovers it.
I have a JavaScript code segment for loading server's data items, and insert them
I have this Javascript code I inherited from another developer. I am very new

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.