MVC验证regex属性可在C#中使用,但不能在JavaScript中使用 [英] MVC validation regex attribute works in C# but not JavaScript
问题描述
我正在尝试通过MVC的正则表达式属性对表单字段进行验证.但是看来,无论我使用什么正则表达式,验证都只能在服务器端进行,而不能在浏览器中进行.
我用于验证的代码是:
[DisplayName("Email Address")]
[Required]
[RegularExpression(@"^[a-zA-Z0-9\.-]*@[a-zA-Z0-9\.]*\.[a-zA-Z\.]{2,6}$", ErrorMessage = "Valid email required.")]
public string emailAddress { get; set; }
正则表达式将无法通过"asd"
,"asd@"
进行验证,但是当不应该通过"asd@asd"
时它将开始通过验证.将正则表达式粘贴到 http://regexpal.com/中将显示该正则表达式仅适用于完整的电子邮件.>
屏幕截图: http://puu.sh/2P05x.png
如果有帮助,则可以在Kendo UI网格编辑弹出窗口中使用.
显然,这是我正在使用的KendoUI版本中的当前已知错误.我不确定是否有适用的更新.此处的更多信息, The regular expression will fail validation with Screenshots: http://puu.sh/2P05x.png If it helps, this is being used in a Kendo UI grid edit pop up. Apparently this is a currently known bug in the version of KendoUI i was using. Im not sure if there is an applicable update for it yet. More information about it here, http://www.kendoui.com/forums/mvc/general-discussions/regular-expression-validator-not-working-in-grid-popup.aspx 这篇关于MVC验证regex属性可在C#中使用,但不能在JavaScript中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!"asd"
, "asd@"
but it starts to pass validation at "asd@asd"
when it shouldn't. Pasting the regular expression into http://regexpal.com/ will show that it should only work with full emails.