开发者

regular expression: trying to include unlimited whitespaces for any words in ASP.NET C#

开发者 https://www.devze.com 2023-02-09 06:37 出处:网络
[RegularExpression(@\"\\S*[a-z\\s]\\S*\\s*\", ErrorMessage = \"Please add category name letters only\")]
[RegularExpression(@"\S*[a-z\s]\S*\s*", ErrorMessage = "Please add 
category name letters only")]

This works fine if I input some words something like this...test test. But if I try to do this... test test test, I will get the ErrorMessage that I implemented. The t开发者_开发问答hing is that I don't know how many words are going to put in by the end user. Is there a way where unlimted whitespaces could put in place? Could some tell me how to do this? Thanks in advance. I am using VS2010


([a-zA-Z\s]{1,})

use regex from above to resolve your problem. Baically a-zA-Z will match any word case insensitive, and \s will match any whitespace character and {1,} will tell that this combination needs to have one or any number of matches.

I hope this helps

0

精彩评论

暂无评论...
验证码 换一张
取 消