Windows窗体中的验证码 [英] validation code in windows form

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

问题描述

我只是想知道该代码将返回false,如以下代码所示.文本框中的值将为空格.并且也只允许使用字母和数字,它们都不会返回false.我可以像以前所说的那样以Windows形式执行此操作吗?有什么东西

I just want to know the code of that will return false like the below code. When value in textbox will be space. And also only alphabets and numbers are allowed neither it will return false. Can i do this in windows form like which i had said? Is there any kind of stuff

private bool ValidateNumbers()
        {
            if (textBox2.Text == string.Empty)
            {
                return true;
            }
            char[] testArr = textBox2.Text.ToArray();
            bool stat = false;
            for (int i = 0; i < testArr.Length; i++)
            {
                if (!char.IsNumber(testArr[i]))
                {
                    stat = true;
                }
            }
            return stat;
        }



代码是正确的)



code is correct )

推荐答案

我认为,最好的主意是使用 ^ ]类.

这是有用的链接的集合:
http://regexlib.com/DisplayPatterns.aspx?cattabindex=2&categoryId=3& AspxAutoDetectCookieSupport = 1 [ ^ ]
http://forums.asp.net/t/897862.aspx/1 [ ^ ]
http://www.regular-expressions.info/numericranges.html [使用正则表达式简化验证 [
In my opinion, the best idea is to use RegEx[^] Class.

Here is the collection of helpful links:
http://regexlib.com/DisplayPatterns.aspx?cattabindex=2&categoryId=3&AspxAutoDetectCookieSupport=1[^]
http://forums.asp.net/t/897862.aspx/1[^]
http://www.regular-expressions.info/numericranges.html[^]
Validation with Regular Expressions Made Simple[^]


您更好的解决方案是使用正则表达式.根据您的问题的正则表达式为"^[a-zA-Z0-9]*
Your better solution would be to use regular expressions. The regular expression based on your question would be "^[a-zA-Z0-9]*


".
这是一个正则表达式教程:
30分钟正则表达式教程 [ ^ ]
如何在C#中使用它们: dotNet中的正则表达式 [
".
Here is a regex tutorial: The 30 Minute Regex Tutorial[^]
How to use them in C#: Regular Expressions in dotNet[^]


这篇关于Windows窗体中的验证码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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