textbox validation for allow one “ . ” value c#

后端 未结 8 1694
悲&欢浪女
悲&欢浪女 2021-01-23 08:56

I want textbox validation for allowing only one . value and only numbers. Means my textbox value should take only numerics and one . value. Value shoul

8条回答
  •  被撕碎了的回忆
    2021-01-23 09:49

    try this code and just replace what you want input type 'validinpu' string.

    try
    {
        short charCode = (short)Strings.Asc(e.KeyChar);
        string validinput = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789 .";
        if (Strings.InStr(validamt, Conversions.ToString(Strings.Chr(charCode)), Microsoft.VisualBasic.CompareMethod.Binary) == 0)
        {
            charCode = 0;
        }
        if (charCode == 0)
        {
            e.Handled = true;
        }
    }
    

提交回复
热议问题