hi
i have a javascript function for asp.net during keypress event for a custom textbox which only allow numbers to be enter.
this textbox have a property of decimalplace. which indicating how many decimal places the text is.
in my function
var key = window.event ? e.keyCode : e.which; var keychar = String.fromCharCode(key); var reg = null var input_value = input_value; var objdecimal = decimal; if (objdecimal > 0) { reg = new RegExp("[0-9,.]"); } else { reg = new RegExp("[0-9]"); } //if (key == 8) { // keychar = String.fromCharCode(key); //} //if (key == 13) { // key = 8;, // keychar = String.fromCharCode(key); //} return reg.test(keychar);
allow user to enter number if decimal =0 if >0 then he or she will be allow to enter comma or dot. but the problem is
if there is a . or , i wan to stop user from keying in . or , again if there is already contain both of this.
example
accepted value
1.00
1,00
1,000.00
1.000,00
not accepted
1.000.00
1,000,00
or
1,,000..
1..00.00