RegularEx pressionAttribute - 如何使它不区分用于客户端验证敏感? [英] RegularExpressionAttribute - How to make it not case sensitive for client side validation?

查看:106
本文介绍了RegularEx pressionAttribute - 如何使它不区分用于客户端验证敏感?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我使用的客户端验证的字符串:

 私人常量字符串的regex ​​= @^(:\\ B(:\\ D {5}(:\\ S *  -  \\ S * \\ D {5})???? ???|([AZ] {2})\\ D {3}(?:\\ S *  -  \\ S * \\ 1 \\ D {3}))(:\\ S *))+ $;

我用这串在我的 [RegularEx pression(正则表达式,的ErrorMessage =无效)] 属性。

我知道为JavaScript正则表达式/ I 标志来使其不区分大小写,只是套结它放在我的正则表达式的末端(即 @^ .... $ /我不工作 - 正则表达式验证彻底失败了,无论是输入的内容(有效与否)

我在想什么?


解决方案

 私人常量字符串的regex ​​= @^(?:\\ B(?:\\ð{5}(?: \\ S *  -  \\ S * \\ D {5})|([A-ZA-Z] {2})\\ D {3}(?:?\\ S *  -  \\ S * \\ 1 \\ D {3}) ??)(?:\\ S *))+ $;

I have a string that I use for client side validation:

private const String regex = @"^(?:\b(?:\d{5}(?:\s*-\s*\d{5})?|([A-Z]{2})\d{3}(?:\s*-\s*\1\d{3})?)(?:,\s*)?)+$";

I use this string in my [RegularExpression(regex, ErrorMessage = "invalid")] attribute.

I know that the /i flag for a Javascript regex is used to make it case insensitive, but just tacking it on to the end of my regex (i.e. @"^....$/i" isn't working - the regex validation fails completely, regardless of what is entered (valid or not).

What am I missing?

解决方案

private const String regex = @"^(?:\b(?:\d{5}(?:\s*-\s*\d{5})?|([a-zA-Z]{2})\d{3}(?:\s*-\s*\1\d{3})?)(?:,\s*)?)+$";

这篇关于RegularEx pressionAttribute - 如何使它不区分用于客户端验证敏感?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆