简体   繁体   English

.NET正则表达式帮助

[英].NET Regular Expression Help

I'm trying to validate an input field value that has the following validatino rules: 我正在尝试验证具有以下validatino规则的输入字段值:

  1. Either a number, OR 一个数字,或者
  2. A number with a trailing 'A', 'K', or 'W' 带后缀“ A”,“ K”或“ W”的数字

some valid values : '1', '12', '1A', '12W' some invalid values : 'A', 'abc', '11A1', '1 A' 一些有效值:'1','12','1A','12W'一些无效值:'A','abc','11A1','1A'

Any pointer appreciated. 任何指针表示赞赏。 Thx 谢谢

/^\d+[AKW]?$/

\\d+ means one or more digits. \\d+表示一个或多个数字。 [AKW]? matches one A or K or W, or nothing ( ? could be interpreted as meaning "optional"). 匹配一个A或K或W,或者不匹配( ?可以解释为“可选”的意思)。 The ^ and $ are anchors that match the start and end of the string respectively. ^$是分别与字符串的开头和结尾匹配的锚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM