本文介绍了如何验证asp.net中的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,请帮帮我,

我必须通过正则表达式或javascript验证asp.net中的文本框.该用户不能输入任何字母.他们只能在文本框中输入小数.

hi all please help me,

i have to validate textbox in asp.net through regular expression or javascript
that user can not enter any alphabets. They can only enter decimal number into textbox.

推荐答案

<asp:textbox id="txt_qty" runat="server" columns="2"></asp:textbox>

<asp:requiredfieldvalidator id="r1" runat="server" errormessage="*" controltovalidate="txt_qty"></asp:requiredfieldvalidator>

<asp:regularexpressionvalidator id="regular1" controltovalidate="txt_qty" runat="server" errormessage="*" validationexpression="^\d+





这样,您的问题将得到解决...




this way your problem will solve...


<ajaxToolkit:FilteredTextBoxExtender ID="ftbe" runat="server"
    TargetControlID="TextBox3"
    FilterType="Custom, Numbers"
    ValidChars="." />



2.使用javscript

< script type ="text/javascript">
//价格文本框只允许数字,只允许2个小数点
函数extractNumber(obj,decimalPlaces,allowNegative)
{
var temp = obj.value;

//如果格式正确,请避免更改内容
var reg0Str =''[0-9] *'';
if(decimalPlaces> 0){
reg0Str + =''\\.?[0-9] {0,''+小数位数+''}'';
}否则,如果(decimalPlaces< 0){
reg0Str + =''\\.?[0-9] *'';
}
reg0Str = allowNegative吗? ''^-?''+ reg0Str:''^''+ reg0Str;
reg0Str = reg0Str +''



2.using javscript

<script type="text/javascript">
// price text-box allow numeric and allow 2 decimal points only
function extractNumber(obj, decimalPlaces, allowNegative)
{
var temp = obj.value;

// avoid changing things if already formatted correctly
var reg0Str = ''[0-9]*'';
if (decimalPlaces > 0) {
reg0Str += ''\\.?[0-9]{0,'' + decimalPlaces + ''}'';
} else if (decimalPlaces < 0) {
reg0Str += ''\\.?[0-9]*'';
}
reg0Str = allowNegative ? ''^-?'' + reg0Str : ''^'' + reg0Str;
reg0Str = reg0Str + ''


这篇关于如何验证asp.net中的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 13:54