遮罩的文字框 [英] Masked textbox

查看:50
本文介绍了遮罩的文字框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何制作仅包含双精度数字的文本框?

How can i make a textbox which takes only double numbers??

推荐答案

通常,方法是不同的:您验证用户输入,仅接受表示双精度值的值数字.
输入无效时,会向用户提示消息错误.
:)
Usually the approach is different: you validate the user input, accepting only values representing double numbers.
On invalid input a message error is prompted to the user.
:)


我认为您需要在触发文本框的keypress事件时验证数字.

只需使用Javascript即可:

I think you need to validate the number when keypress event is triggered for the textbox.

Just use Javascript to do that :

function check_double(e,fieldid)
{
     var field = document.getElementById(fieldid);
     if (!(((e.keyCode>=48)&&(e.keyCode<=57))||(e.keyCode==46)))
     {
        e.returnValue = false;        
        e.keyCode=0;                   
     }     
     if (e.keyCode==46)
     {
        var patt1=new RegExp("\\.");        
        var ch =patt1.exec(field);       
        if(ch==".")
        {
            e.returnValue = false;
            e.keyCode=0;
        }                        
     }
} 


现在,在您的Page_Load中使用以下代码:


Now in your Page_Load use this :

TextBox.Attributes.Add("onkeypress", "javascript:check_double(event,''" + TextBox.ClientID + "'');");



只需将其放置在要验证Double的每个文本框中即可.

希望您喜欢该解决方案.
干杯
:rose:



Just place this for every textbox for which you want to validate Double.

I hope you will like the solution.
Cheers
:rose:


这篇关于遮罩的文字框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆