struts2 ognl 正则表达式-asp
本文介绍了asp.net mvc 4 中的 验证(正则表达式)-剃刀视图的处理方法struts2 ognl 正则表达式,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当在正则表达式中使用特殊字符时, 验证器在 asp.net mvc 4 razor 视图中不起作用.
The not in asp.net mvc 4 razor view, when using the in the .
型号:
[StringLength(100)]
[Display(Description = "First Name")]
[RegularExpression("^([a-zA-Z0-9 .&'-]+)$", ErrorMessage = "Invalid First Name")]
public string FirstName { get; set; }
剃刀视图:
@Html.TextBoxFor(model => Model.FirstName, new )
@Html.ValidationMessageFor(model => Model.FirstName)
不显眼的验证在视图中呈现为:
The is in view as:
上述html中的regex模式没有按照Model的中指定的方式呈现,导致即使输入有效数据(Sam's)也会出错.
The regex in the above html is not as in the Model’s , which in error even when the valid data (Sam's).
我该如何处理?
–更新–
我已经按照@Rick 的建议更新了代码
I have the code as per @Rick
[StringLength(100)]
[Display(Description = "First Name")]
[RegularExpression("([a-zA-Z0-9 .&'-]+)", ErrorMessage = "Enter only alphabets and numbers of First Name")]
public string FirstName { get; set; }
查看源代码显示以下内容:
View Source shows the :
我还是有同样的问题.
推荐答案
2012 年 7 月 9 日更新 – 看起来这已在 RTM 中修复.
UPDATE 9 July 2012 – Looks like this is fixed in RTM.
我们已经暗示了 ^ 和 $ 所以你不需要添加它们.(包含它们似乎没有问题struts2 ognl 正则表达式,但您不需要它们)这似乎是 ASP.NET MVC 4//Beta 中的一个错误.我打开了一个错误
We imply ^ and $ so you don’t need to add them. (It doesn’t appear to be a to them, but you don’t need them)This to be a bug in ASP.NET MVC 4//Beta. I’ve opened a bug
查看源码显示如下:
data-val-regex-pattern="([a-zA-Z0-9 .&'-]+)"
[1]: https://xuan.ddwoo.top/index.php/archives/540/
相关文章
- Java编程中忽略这些细节,Bug肯定找上你
- 9个问题,带你掌握流程控制语句中的java原理
- 从IDC Marketscape报告看区块链政务数字化未来:权威解读新热点、新机遇
- chatGPT的火爆,并不偶然
- React 开发 | 常用 Hooks
- JDK19都出来了~是时候梳理清楚JDK的各个版本的特性了【JDK12特性讲解】
- Eolink 让我“重新认识“了自动化测试...
- 老板:你也把咱们网站弄成灰色——网站变灰色如何实现
- iptables规则案例
- ‘极锐’-一种新的锐化算法
- PS/LR滤镜插件套装 Nik Collection v5.3.0 Win/Mac
- Chrome插件:uBlock Origin – Chrome浏览器高效低占用的广告拦截插件
- 前端与区块链
- 云原生之微服务
- 集群动态环境管理神器 Modules
- 记 os_object_release Crash 排查
- 记 libAccessibility 通知 Crash 排查
- Ant Design Pro 中 点击子菜单的时候,其他菜单不自动收起来
- ETC 可视化
- 1267-Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_0900_ai_ci,IMPLIC for o...