为全名设置验证错误 [英] SET VALLIDATION ERROR FOR FULL NAME
问题描述
HIII
我想为没有名字和特殊字符的姓氏(空格),姓氏(空格),中间名等全名设置验证
使用常规表达
在开始新帖子之前,请先将有用的帖子标记为答案,以结束之前的主题.>
第二,这实际上不是WPF主题.有一个有关C#相关问题的C#论坛: https://social.msdn.microsoft.com/Forums/vstudio/zh-CN/home?forum=csharpgeneral
无论如何,以下正则表达式正好匹配三个名称,并且两者之间有一个空格:
正则表达式regex = new Regex(@"^ [a-zA-Z] + [\ s] [a-zA-Z] + [\ s] [a-zA-Z] +
"); 字符串名称="first last mid5dle"; 如果(regex.IsMatch(name)) { //... }这与两个或三个名称匹配,以防姓氏(中间)是可选的:
正则表达式regex =新正则表达式(@"^ [a-zA-Z] + [\ s] [a-zA-Z] + [\ s] * [a-zA-Z] *
");希望有帮助.
请记住,通过将有用的帖子标记为答案来关闭话题,然后在遇到新问题时开始新话题.请不要在同一线程中问几个问题.
HIII
I WANT TO SET VALIDATION FOR FULL NAME LIKE LASTNAME (SPACE) FIRSTNAME (SPACE) MIDDLENAME WITH NOT ALLOW NUMBER AND SPECIAL CHARACTER
USE REGULAR EXPRESSION
Please close your previous threads by marking helpful posts as answer before you start a new one.
And second, this is not really a WPF topic. There is a C# forum for C# related questions: https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=csharpgeneral
Anyway, the following regular expression matches exactly three names with a single space in between:
Regex regex = new Regex(@"^[a-zA-Z]+[\s][a-zA-Z]+[\s][a-zA-Z]+
"); string name = "first last mid5dle"; if (regex.IsMatch(name)) { //... }This matches two or three names in case the last (middle) name is optional:
Regex regex = new Regex(@"^[a-zA-Z]+[\s][a-zA-Z]+[\s]*[a-zA-Z]*
");Hope that helps.
Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.
这篇关于为全名设置验证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!