问题描述
我不确定怎么做,因为我不知道如何开始
它只允许两位小数,但我想只允许小数位前的数字
我尝试过:
< asp:TextBox ID =txtraterunat = server>
函数validateFloatKeyPress(el,evt){
var charCode =(evt.which)? evt.which:event.keyCode;
var number = el.value.split('。');
if(charCode!= 46&& charCode> ; 31&&(charCode< 48 || charCode> 57)){
返回false;
}
//只有一个点
if(number.length> 1&& charCode == 46){
返回false;
}
//获得克拉位置
var caratPos = getSelectionStart(el);
var dotPos = el.value.indexOf(。) ;
if(caratPos> dotPos&& dotPos> -1&&(number [1] .length> 1)){
return false;
}
返回true;
}
函数getSelectionStart(o){
if(o.createTextRange){
var r = document.selection.createRange()。duplicate()
r.moveEnd( character',o.value.length)
if(r.text =='')return o.value.length
return o.value.lastIndexOf(r。文本)
}否则返回o.selectionStart
}
i am unsure how to do it as i do not know how to start
It allows only two decimal places but i want to allow only a digit before decimal place also
What I have tried:
<asp:TextBox ID="txtrate" runat="server" >
function validateFloatKeyPress(el, evt) {
var charCode = (evt.which) ? evt.which : event.keyCode;
var number = el.value.split('.');
if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57)) {
return false;
}
//just one dot
if (number.length > 1 && charCode == 46) {
return false;
}
//get the carat position
var caratPos = getSelectionStart(el);
var dotPos = el.value.indexOf(".");
if (caratPos > dotPos && dotPos > -1 && (number[1].length > 1)) {
return false;
}
return true;
}
function getSelectionStart(o) {
if (o.createTextRange) {
var r = document.selection.createRange().duplicate()
r.moveEnd('character', o.value.length)
if (r.text == '') return o.value.length
return o.value.lastIndexOf(r.text)
} else return o.selectionStart
}
推荐答案
这篇关于ASP.NET中一个数字和两个十进制值的文本框验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!