Javascript/Jquery validating decimal input on keyup -


i'm trying find way validate text input on key press, want allow numbers inside text input including decimals. taking approach of using jquery.keydown, , checking key , using.

input numbers max length 999.999

-

my result after . (point) 3 number goog. 99999.999

i need 999.999,222.222,22.01 -> max length +++.+++

this code

<input type="text" id="spinedit2" class="aspinedit" />  <script type="text/javascript"> var txt = document.getelementbyid('spinedit2');     txt.addeventlistener('keyup', myfunc);      function myfunc(e) {         var val = this.value;          var re1 = /^([0-9]+[\.]?[0-9]?[0-9]?[0-9]?|[0-9])/g;             val = re1.exec(val);             //console.log(val);             if (val) {                 this.value = val[0];             } else {                 this.value = "";             }      } </script> 

thanks

how about

/^([0-9]{1,3}(?:\.[0-9]{0,3})?)/g 

in case want details: {1,3} means preceding thing can happen 1 3 times. (?:) non-captured group -- it's grouping of following symbols, doesn't capture variables $1.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -