 |
สอบถาม javascript event.keyCode ใส่ตัวเลข comma(,) จุด(.) อย่างเดียว |
|
 |
|
|
 |
 |
|
<script>
function IsNumeric(sText,obj){
var ValidChars = "0123456789.,";
var IsNumber=true;
var Char;
for (i = 0; i < sText.length && IsNumber == true; i++){
Char = sText.charAt(i);
if (ValidChars.indexOf(Char) == -1){
IsNumber = false;
}
}
if(IsNumber==false){
obj.value="0";
}
}
</script>
<input type="text" name="txt" onKeyUp="IsNumerid(this.value,this)">
|
 |
 |
 |
 |
Date :
2009-10-22 12:28:38 |
By :
kalamell |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
comma key code 44
|
 |
 |
 |
 |
Date :
2009-10-22 15:35:20 |
By :
lozomac |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
<script type="text/javascript">
function CommaFormatted(amount)
{
var delimiter = ","; // replace comma if desired
var a = amount.split('.',2)
var d = a[1];
var i = parseInt(a[0]);
if(isNaN(i)) { return ''; }
var minus = '';
if(i < 0) { minus = '-'; }
i = Math.abs(i);
var n = new String(i);
var a = [];
while(n.length > 3)
{
var nn = n.substr(n.length-3);
a.unshift(nn);
n = n.substr(0,n.length-3);
}
if(n.length > 0) { a.unshift(n); }
n = a.join(delimiter);
if(d.length < 1) { amount = n; }
else { amount = n + '.' + d; }
amount = minus + amount;
return amount;
}
alert(CommaFormatted('10000.2345'));
</script>
ref : http://www.web-source.net/web_development/currency_formatting.htm
|
 |
 |
 |
 |
Date :
2009-10-23 13:44:37 |
By :
num |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณทุกๆ ท่านแทนเจ้าของกระทู้ครับ
|
ประวัติการแก้ไข 2010-11-01 10:18:52
 |
 |
 |
 |
Date :
2010-11-01 10:13:59 |
By :
LeStat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|