正则表达式在C#的RegularExpression属性中不起作用 [英] Regex is not working in RegularExpression attribute on c#
问题描述
伙计们,我不知道这个问题是否已经存在,但是我已经尝试了所有搜索,所以我的问题是为什么我的正则表达式不能在RegularExpression属性中正常工作.我在javascript中使用过的同一个正则表达式,正在javascript上运行.有人可以帮我在这里做错什么吗?
guys, I don't know this question is already present or not but I have tried every search, so my question is why my regex is not working properly in RegularExpression attribute. this same regex I have used in javascript and this is working on javascript. can anyone help me what I am doing wrong here?
[Required]
[Display(Name = "First name")]
[MaxLength(50)]
[RegularExpression("^(?![@\\+\\-=\\*])", ErrorMessage = "First Name Should not start with these characters @, +, =, *, -")]
public string firstname { get; set; }
我正在使用此正则表达式来验证名字,不应以@,+,=,*,-开头.
I am using this regex for validating the First Name should not start with @,+,=,*,-.
我已经花了3个小时来弄清楚我在这里做错了什么.
I have already spent 3 hours to figure out what I am doing wrong here.
推荐答案
我相信您的正则表达式应如下所示:
I believe you regex should look like this:
^(?![@\\+\\-=\\*]).*
这篇关于正则表达式在C#的RegularExpression属性中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!