Regular expression in ASP.NET for validator

时间:2021-06-16 16:35:08

I want regular expression in asp.net validator for below:

我希望asp.net验证器中的正则表达式如下:

2012T8
  1. first must be valid year up to now
  2. 首先必须是有效的一年到现在

  3. second must be character T
  4. 第二个必须是字符T.

  5. third must be any single digit
  6. 第三个必须是任何一个数字

Can anyone help?

有人可以帮忙吗?

1 个解决方案

#1


0  

I usually avoid regex as if not all my team members are familiar with it, our code seems gibberish and easily solvable bugs are missed, so we usually just code the match.

我通常会避免使用正则表达式,好像我的所有团队成员都不熟悉它,我们的代码看起来很乱,很容易解决错误,所以我们通常只是对匹配进行编码。

Naturally regex is blaziongly fast and if you're matching against a lot of data, it's the best way to go.

自然地,正则表达式是快速的,如果你匹配大量的数据,这是最好的方式。

I think what you need is this:

我想你需要的是:

^[1-9]{1}[0-9]{3}[T][0-9]{1}$

The {1} dictates the amount of characters that must meet the match, so it's 1 character for a number > 0, then 3 characters being any number, then the letter T then a single number.

{1}指示必须满足匹配的字符数量,因此对于数字> 0,它是1个字符,然后3个字符是任意数字,然后字母T然后是单个数字。

#1


0  

I usually avoid regex as if not all my team members are familiar with it, our code seems gibberish and easily solvable bugs are missed, so we usually just code the match.

我通常会避免使用正则表达式,好像我的所有团队成员都不熟悉它,我们的代码看起来很乱,很容易解决错误,所以我们通常只是对匹配进行编码。

Naturally regex is blaziongly fast and if you're matching against a lot of data, it's the best way to go.

自然地,正则表达式是快速的,如果你匹配大量的数据,这是最好的方式。

I think what you need is this:

我想你需要的是:

^[1-9]{1}[0-9]{3}[T][0-9]{1}$

The {1} dictates the amount of characters that must meet the match, so it's 1 character for a number > 0, then 3 characters being any number, then the letter T then a single number.

{1}指示必须满足匹配的字符数量,因此对于数字> 0,它是1个字符,然后3个字符是任意数字,然后字母T然后是单个数字。