验证文本框以仅从特定数字范围输入数字 [英] validate textbox to enter number from only particular range of numbers

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

问题描述

在我的窗口应用程序中,我有很多文本框,我想输入一个特定范围的值,如1,2,4,8,11,56,78。我能够验证单个数字,但无法用两位数字来做。我怎样才能从这些数字中验证。请帮助我

解决方案

试试这个...

范围验证从0到78 ..



  public   static   bool  IsValidNo( string  inputNo)
{
string strRegex = @ ^(?:\d | [1-3] \d | 7 [0-8])

;
Regex re = new 正则表达式(strRegex);
if (re.IsMatch(inputEmail))
return );
else
return false );
}





更多参考这个链接


试试这个



如果您只想验证固定值,这就足够了

  private   static   bool  ValidateFixedNumbers( int  number)
{
int [] numbers = { 1 2 4 8 11 56 78 };
return numbers.Contains(number);
}



在某个范围内,你可以使用它。

  private   static   bool  ValidateInRange( int  来自 int  to, int  number)
{
return System.Linq.Enumerable.Range(,到).Contains(数字);

}


In my window application i have many text box and i want to enter a number from particular range of values like 1, 2, 4 ,8, 11, 56, 78. i am able to validate single digit numbers, but unable to do with two digit number. how can i validate from only those numbers. please can you help me

解决方案

Try this...
Range Validation from 0 to 78..

public static bool IsValidNo(string inputNo)
{
    string strRegex = @"^(?:\d|[1-3]\d|7[0-8])


"; Regex re = new Regex(strRegex); if (re.IsMatch(inputEmail)) return (true); else return (false); }



For more refer this link


Try this

If you want to validate only fixed values this will be enough

private static bool ValidateFixedNumbers(int number)
   {
       int[] numbers = { 1, 2, 4, 8, 11, 56, 78 };
       return numbers.Contains(number);
   }


with in a range , you can use this.

private static bool ValidateInRange(int from, int to, int number)
{
    return System.Linq.Enumerable.Range(from, to).Contains(number);

}


这篇关于验证文本框以仅从特定数字范围输入数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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