如何为Windows窗体制作正则表达式 [英] how to make regex for windows forms

查看:223
本文介绍了如何为Windows窗体制作正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的朋友正在制作Windows窗体,他需要提供一个用户名,该用户名的长度至少为4个字符,最长为15个字符.它还将在用户名的中间允许连字符,下划线以及中间的点,但不允许在用户名的开头和结尾.连续最多只能有一个连字符,一个下划线和一个点.
不允许的用户名示例:

My friend is making windows form and he needs to vlidate a username which will be a minimum of 4 characters and maximum of 15 characters long. It will also allow hyphens and underscores as well as dots in the middle, but not at the start and neither at the end of the username. There may be no more than one hyphen, one underscore and one dot in a row.
Examples of disallowed usernames:

-aquib
_aquib
.aquibxyz
aquib.
aquibxyz--qureshi
aquib__xyzqureshi
aquibqureshi-
aquib..qureshi
aquib_     // means no symbols will be there at end


用户名不仅应该是数字,还应该是数字和字母字符的混合,或者只能是字母.
我希望这会被理解
我有这个正则表达式:


The username should not be only digits it should be either a mix of digits and alphabetical characters or it should be only alphabetic.
I hope this will be understood
I have got this regex:

^([a-zA-Z0-9](?(?!__|--)[a-zA-Z0-9_\-]){0,4}[a-zA-Z0-9])$


但这对他来说并不太有用.
有人可以帮帮我吗?

提前谢谢!
P.S.:我已经下载了expresso,但是在那种环境下我还不够.对我来说,这太难理解了.


but it is not too usefull in his case.
Can any one help me out?

Thanks in advance!
P.S.: I have downloaded expresso but I am not sufficient in that environmen. It''s way too difficult to undestand for me.

推荐答案


但这对他来说并不太有用.
有人可以帮帮我吗?

提前谢谢!
P.S.:我已经下载了expresso,但是在那种环境下我还不够.对于我来说,这真是太难理解了.


but it is not too usefull in his case.
Can any one help me out?

Thanks in advance!
P.S.: I have downloaded expresso but I am not sufficient in that environmen. It''s way too difficult to undestand for me.


这里有专门的 ^ ].
There is a dedicated regex forum[^]. The people there will more likely be able to help you than those in the multi-purpose Q&A.


您想要的东西将很难(即使不是不可能)与正则表达式一起使用,但是,如果您同意将长度检查与正则表达式内容分开,则有一种方法可以解决此问题.首先检查用户名的长度是否在指定范围内,如果是,请在此处使用用户名regex:

What you want would be hard, if not impossible, to do with regular expressions, but there is one way you could pull this through if you can agree to separate the length check from the regular expression stuff. First check would be if the length of the username is within the specified bounds and if it is check the username with this here regex:

^(?:[a-zA-Z0-9](?:\.|_|-)?)+[a-zA-Z0-9]


这篇关于如何为Windows窗体制作正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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