【发布时间】:2026-01-26 07:26:01
【问题描述】:
我正在尝试验证用户的输入是否仅插入字母数字字符,包括特殊字符,如 .,_ 空格。
Point 1. the user cant insert only special characters like @@@@@@@ or .........
Point 2. or any numeric numbers like 2222222.
它应该是任何有效的格式,例如。 "hi i am asking a question on stack overflow.this is my 11th attempt. "
我尝试了这些表达方式,但它不允许我像第 1 点和第 2 点那样限制用户,请帮助。
这是我的代码
[RegularExpression(@"^([a-zA-Z0-9 \.\&\'\-]+)$", ErrorMessage = "Invalid User Name")]
public string UserName { get; set; }
[Required]
[StringLength(250, MinimumLength = 5, ErrorMessage = "User Description must have minimum 5 and maximum 250 characters.")]
[RegularExpression(@"^[^<>!@#%/?*]+$", ErrorMessage = "Invalid User Description")]
public string Description { get; set; }
【问题讨论】:
标签: regex asp.net-mvc-4 data-annotations