文本框只接受像XX,YY格式的数字意味着12,45是12.34,23.45之类的 [英] Textbox accepct only numbers like XX,YY format means 12,45 are 12.34,23.45 like
本文介绍了文本框只接受像XX,YY格式的数字意味着12,45是12.34,23.45之类的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hai All,
i在asp.net中有一个文本框,它只接受数字和小数,格式为XX,YY不超过两个nnumbers意味着
ex:12,45
12.45,24.5
0.57 ,34.56
不喜欢这个错误:
Ex:12.34.34,23.45
,23.346,34
那么它会显示错误
plz任何人都非常紧急帮助我
Hai All,
i have a text box in asp.net it will accept only number and decimals only in the format of XX,YY not more than two nnumbers means
ex:12,45
12.45,24.5
0.57,34.56
not like this error:
Ex:12.34.34,23.45
,23.346,34
then it will show error
plz any one help me very urgent
推荐答案
您好,
基本上您可以为此使用Javascript / Jquery。您应该为每个文本框分配一个特定的类,例如amount,amountlbl。有数字的标签。
数字应该是这样的:-12345到12,345而不是1,23,45表示3的倍数。但你可以修改正则表达式/函数符合你的要求[CommaSepratedValues]。我已经厌倦了这个代码用于文本框或标签中的单个数字。我已经将CSS类数量分配给文本框并标记为amountlbl。
这是使用正则表达式的Java脚本代码
Hello,
Basically You Can Use Javascript/Jquery for this for this.you should assign a specific class such as amount , amountlbl to each textbox & label having number.
The Number should be like this :-12345 to 12,345 not 1,23,45 means in multiple of 3's. But you can modify the regular expression/functions to your requirements[CommaSepratedValues].I have tired this code for single number in textbox or label.I have assisgned a CSS class amount to textbox and label as amountlbl.
Here is the Java Script Code Using Regular expression
function CommaSepratedValue(nStr)
{ try{
if(nStr!=undefined || nStr !=null){
nStr = nStr.replace(/,/g,'');
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;//For 2 numbers replace d{3} to d{2}
while (rgx.test(x1))
x1 = x1.replace(rgx, '
1' + ' , + '
1' + ',' + '
2' );
return x1 + x2;
}
}
catch (呃){
return nStr;
}
}
2'); return x1 + x2; } } catch(er){ return nStr; } }
现在给head标签中对jquery库的引用
最后写一下
Now give the reference to jquery library in head tag
In the end write
这篇关于文本框只接受像XX,YY格式的数字意味着12,45是12.34,23.45之类的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文