Regex to only allow 15 digits length?

时间:2017-06-20 12:38:33

标签: javascript jquery validation

I am using below code for regular expression handling but i need to handle only(accepting) 15 digits

([0-9]{2}[a-zA-Z]{4}([a-zA-Z]{1}|[0-9]{1}).[0-9]{3}[a-zA-Z]([a-zA-Z]|[0-9]){3})

This code working fine as per logic but not control only 15 digits Please help me how to control it?

2 个答案:

答案 0 :(得分:0)

这将正则表达式控制为15位数。您可以将其更改为{0, 15}以指定允许的最小和最大位数

(?=.{15}$)(([0-9]{2}[a-zA-Z]{4}([a-zA-Z]{1}|[0-9]{1}).[0-9]{3}[a-zA-Z]([a-zA-Z]|[0-9]){3}))

答案 1 :(得分:0)

本网站可以帮助您学习正则表达式:https://regex101.com/
它允许您构建,测试和理解您的正则表达式。

举个例子,这里是量词的快速参考: enter image description here