.NET正防爆pression从任何语言相匹配任何种类的信相匹配、种类、语言、NET

2023-09-04 07:49:13 作者:夜幕篱下浅笙歌°

这经常EX pression我可以用它来搭配(允许)任何形式的字母,从任何语言

Which regular expression can I use to match (allow) any kind of letter from any language

我需要匹配任何字母,包括任何变音符号(如A,U,N等) 并排除任何一种符号(数学符号,货币符号,装饰符号箱绘制字符等)和标点字符。

I need to match any letter including any diacritics (e.g. á, ü, ñ, etc.) and exclude any kind of symbol (math symbols, currency signs, dingbats, box-drawing characters, etc.) and punctuation characters.

我使用asp.net MVC 2 .NET 4。我已经试过这个注释在我看来,型号:

I'm using asp.net MVC 2 with .net 4. I've tried this annotation in my view model:

[RegularExpression(@"\p{L}*", ...

和这一个:

[RegularExpression(@"\p{L}\p{M}*", ...

但客户端验证无法正常工作。

but client side validation does not work.

更新: 谢谢你所有的答案,您的建议工作,但只对.net和这里的问题是,它也采用了客户端验证的正则表达式使用JavaScript(抱歉,如果这还不够清楚)。 我只好去:

UPDATE: Thank you for all your answers, your suggestions work but only for .net and the problem here is that it also uses the regex for client side validation with JavaScript (sorry if this was not clear enough). I had to go with:

[^ 0-9_ \ |°¬#\ $%/ \()\¡¿+ {} []:?\; @ª^ *<> =&放大器;] *

这是非常丑陋,并不包括所有的情况反而是最接近我所需要的。

which is very ugly and does not cover all scenarios but is the closest thing to what I need.

推荐答案

有一点需要注意的是客户端的正则表达式。它使用在客户端和.NET正则表达式在服务器端JavaScript的正则表达式。 JavaScript就无法支持此方案。

One thing to watch out for is the client-side regex. It uses javascript regex on the client side and .net regex on the server side. Javascript won't support this scenario.

 
精彩推荐
图片推荐