我需要验证文本框为数字 [英] I need to validate a textbox as numbers

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

问题描述

我只将javascript用于键入数字.文本框名称为txtFromDay.
但是现在我无法输入任何内容.由于脚本返回false.
U使用alert()方法显示键入的数据,但结果为空白消息.请问原因和解决方法.
脚本如下

I used a javascript for only type numbers. Textboxname as txtFromDay.
But now I can''t type any. Because of script returns false.
U used a alert() method for display the typed data,But It result as blank message. What is the reason and solution.
script as below

function Checkprice(e)
    {
    var ups=document.getElementById('<%=txtFromDay.ClientID%>').value;
                     if (e.keyCode >= 48 & e.keyCode <= 57)
                        {
                        alert(ups);
                           return true;
                        }
                    else
                        {
                        alert(ups);
                        return false;
                        }
    }

推荐答案

您正在使用按位AND .....

You are using a bitwise AND .....

if (e.keyCode >= 48 & e.keyCode <= 57)



您需要逻辑AND .....(两个&'s)



You need a logical AND ..... (two &''s)

if (e.keyCode >= 48 && e.keyCode <= 57)


使用"RegularExpressionValidator"可能是检查文本框值是否为数字且不浪费时间的最佳方法.

请参见仅使用正则表达式验证器在ASP.NET文本框中进行数字验证
maybe best way to check if your textbox value is number and don''t lost your time, to use "RegularExpressionValidator"

see here Only Number validation in Textbox of ASP.NET Using Regular Expression validator


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

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