正则表达式验证在ASP.Net中不适用于中国文化

时间:2022-10-28 16:39:33

I have a regular expression validator with client-side validation disabled in an ASP.Net change. The regular expression being used for this validator is as below and it is validating input into a Product Description multi-line text box.

我有一个正则表达式验证器,在ASP中禁用了客户端验证。净改变。用于该验证器的正则表达式如下所示,它将验证输入到产品描述多行文本框中。

 Expression="^[\\p .,;'\-(0-9)\(\)\[\]]+$"

The culture for this ASP.Net app is Chinese as specified in web config.

这种ASP的文化。Net app是web配置中指定的中文。

<globalization uiCulture="zh" culture="zh-CHT" />

The following input into Product Description text box in same ASP.Net page is always failing. I am trying to match any one of these: chinese langauge character or period or comma or semi-colon or single quote or digits or round/square brackets.

以下输入到产品描述文本框中。Net页面总是失败。我正在尝试匹配其中的任何一个:中文语言字符、句号、逗号、分号、单引号、数字或圆括号。

Question: What is in the regular expression that is causing this input text to fail and how can I change it to satisfy the matching requirements?

问题:导致输入文本失败的正则表达式中是什么,我如何更改它以满足匹配要求?

(1)降低庫存過程 (2)增加了吞吐量(1)降低庫存過程 (2)增加了吞吐量(1)降低庫存過程 (2)增加了吞吐量(1)降低庫存過程 (2)增加了吞吐量

(1)降低庫存過程(2)增加了吞吐量(1)降低庫存過程(2)增加了吞吐量(1)降低庫存過程(2)增加了吞吐量(1)降低庫存過程(2)增加了吞吐量

1 个解决方案

#1


3  

In .NET regex, the one that works on server side, you can make use of Unicode categories.

在服务器端工作的. net regex中,可以使用Unicode类别。

^[\p{L}\p{M}\p{N}\s\p{P}]+$

See demo

看到演示

So, the character class matches:

因此,字符类匹配:

  • \p{L} - Unicode letters
  • \ p { L } - Unicode信件
  • \p{M} - diacritic marks
  • \ p { M } -可区别的标志
  • \p{N} - numbers
  • \ p { N } -数字
  • \s - whitespace
  • \ s -空白
  • \p{P} - punctuation.
  • \ p { p } -标点符号。

Note these Unicode categories won't work on client-side where your Englsh UI culture validation takes place. You can use your fixed expression there:

请注意,这些Unicode类别不会在客户端进行,因为您的Englsh UI文化验证发生了。你可以用你的固定表达:

^[a-zA-Z .,;'\-0-9()\[\]]+$

See demo

看到演示

#1


3  

In .NET regex, the one that works on server side, you can make use of Unicode categories.

在服务器端工作的. net regex中,可以使用Unicode类别。

^[\p{L}\p{M}\p{N}\s\p{P}]+$

See demo

看到演示

So, the character class matches:

因此,字符类匹配:

  • \p{L} - Unicode letters
  • \ p { L } - Unicode信件
  • \p{M} - diacritic marks
  • \ p { M } -可区别的标志
  • \p{N} - numbers
  • \ p { N } -数字
  • \s - whitespace
  • \ s -空白
  • \p{P} - punctuation.
  • \ p { p } -标点符号。

Note these Unicode categories won't work on client-side where your Englsh UI culture validation takes place. You can use your fixed expression there:

请注意,这些Unicode类别不会在客户端进行,因为您的Englsh UI文化验证发生了。你可以用你的固定表达:

^[a-zA-Z .,;'\-0-9()\[\]]+$

See demo

看到演示