<input onpropertychange="if(isNaN(Number(this.value))){alert();this.focus()}">

解决方案 »

  1.   

    <input onblur="if(isNaN(Number(this.value))){alert();this.focus()}">
      

  2.   

    只能用javascript
    感觉客户端压力很大,只不过没关系
      

  3.   

    告诉你一个服务端的检验方法:private static Regex _isNumber = new Regex("^[0-9]+$");
    //是否数字字符串
    public static bool IsNumber(string inputData)
    {
    Match m = _isNumber.Match(inputData);
    return m.Success;
    }
      

  4.   

    private System.Windows.Forms.TextBox textBox1;
    private string text;
    public Form1()
    {
       text = textBox1.Text;
    }
    private void textBox1_TextChanged(object sender, System.EventArgs e)
    {
        int len = text.Length;
    if(len < textBox1.Text.Length)
    {
           int index = textBox1.Text.IndexOf(text);
           char c = (textBox1.Text.Remove(index,text.Length))[0];
           if(c.CompareTo('0') < 0||c.CompareTo('9') >0)
           {
               textBox1.Text = text;
               textBox1.SelectionStart = text.Length;
           }
         }
        text = textBox1.Text;
               
    }
      

  5.   

    我们知道,在C#中,TextBox控件对输入字符的控制有keypress、keyup、和keydown事件来使用,但大家也看到了,这几个事件对输入字符的控制都有一定的缺陷,如果,你使用中文输入法,那么很多原来你不希望输入的字符也可以输入进去。这几天做程序的时候,就碰到了这个问题,我的解决思路很简单,既然这三个事件不再起作用,那么我就使用了TextBox控件中时刻能发生的TextChanged事件,以期望在这个事件中作些东西,以达到控制字符的目的。废话就不多说了,我将控制输入字符为数字的代码粘贴出来,希望大家多指正,如果能对你有益的话,我就更happy了。 
    private System.Windows.Forms.TextBox textBox1;
    private string text;
    public Form1()
    {
       text = textBox1.Text;
    }
    private void textBox1_TextChanged(object sender, System.EventArgs e)
    {
        int len = text.Length;
    if(len < textBox1.Text.Length)
    {
           int index = textBox1.Text.IndexOf(text);
           char c = (textBox1.Text.Remove(index,text.Length))[0];
           if(c.CompareTo('0') < 0||c.CompareTo('9') >0)
           {
               textBox1.Text = text;
               textBox1.SelectionStart = text.Length;
           }
         }
        text = textBox1.Text;
               
    }
      

  6.   

    textBox里的TextChanged事件怎么不执行呢?
      

  7.   

    孟子的javascript应该放在哪里?
      

  8.   

    用RegularExpressionValidator
    靠正则表达式判断
      

  9.   

    litp(天道酬勤) 
    正确!
      

  10.   

    to  windycloudycrazy(辽远) ( ) 信誉:100  2004-07-21 23:19:00  得分: 0  
     AutoPostBack 设为true
      

  11.   

    这种小问题不需要用到正则表达式,根据ASCII码来判断0-9的字符,即<0或者>9的都不是数字。至于你说的不能响应事件。就像楼上的兄弟说的,AutoPostBack属性没有设置为true.