简体   繁体   English

HTML5 验证问题

[英]HTML5 Validation issue

I'm trying to validate input using HTML5 pattern tag.我正在尝试使用 HTML5 pattern标记验证输入。 Have 3 separate input checks:有 3 个单独的输入检查:

  • upper or lower case characters from ae range, 1 character limit [A-Ea-e]{1} For example: A, B, e ... ae 范围内的大写或小写字符,1 个字符限制[A-Ea-e]{1}例如:A、B、e ...
  • only numbers and comma.只有数字和逗号。 Comma is not first or last character of string.逗号不是字符串的第一个或最后一个字符。 [0-9]+,*[0-9]+ For example: 0,52356, 0677,67 ... [0-9]+,*[0-9]+例如:0,52356, 0677,67 ...
  • upper or lower case characters from ae range, 1 character limit [A-Ea-e]{3} for example: AbE, cDa ae 范围内的大写或小写字符,1 个字符限制[A-Ea-e]{3}例如:AbE、cDa

I want to add to all of this samples or * sign with 1 char limit condition.我想添加到所有这些样本or * sign with 1 char limit条件。

For every check that listed above there might be 1 * sign which is also accepted.对于上面列出的每张支票,可能会有 1 个 * 符号也被接受。 But if there is * sign, adding more characters must end with invalid result.但是如果有*号,增加更多的字符必须以无效结果结束。

I'm new to regex.我是正则表达式的新手。 Can not figure out.想不通。

Any suggestions?有什么建议?

^([A-Ea-e]{1}|[0-9]+(,[0-9]+)*|[A-Ea-e]{3})\*?$

Valid:有效的:

A
AAA
1
1,2
1,2,3
A*
AAA*
1*
1,2*
1,2,3*

Invalid:无效的:

AA
AAAA
,1
1,
1,**

If you want them separate:如果你想让它们分开:

^[A-Ea-e]{1}\*?$
^[0-9]+(,[0-9]+)*\*?$
^[A-Ea-e]{3}\*?$

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

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