0

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?

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Shreya
  • 61
  • 2
  • 5
  • 14
  • How you looked at theese ? 1. https://stackoverflow.com/questions/11197549/regular-expression-limit-string-size 2. https://stackoverflow.com/questions/8246482/how-to-use-regex-lookahead-to-limit-the-total-length-of-input-string – Eriks Jun 20 '17 at 12:42
  • Not working (/^(?=.{1,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}) – Shreya Jun 20 '17 at 12:57
  • Why don't you just use this regex and then check if the string.length is <= 15? – Mμ. Jun 20 '17 at 13:00
  • Because i need one line validation – Shreya Jun 20 '17 at 13:23

2 Answers2

0

This controls the regex to 15 digits. you can change it to {0, 15} to specify the minimum and maximum digits allowed

(?=.{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}))
Varun
  • 241
  • 1
  • 9
0

This website can help you out with learning regex: https://regex101.com/
It allows you to build, test and understand your regular expressions.

As an example, here's the quick reference for quantifiers: enter image description here

rozerocool
  • 160
  • 2
  • 8