Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to handle something like [1,2,3] with html5 input type text?

I would like to know if we can handle specific input like the following examples using pattern:

[1] or
[1,2]

so basically brackets with a number or if there are more numbers then only comma allowed as a separator.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Tried [(\d+(\s*,?))+] as stated below but it doesn’t work.

>Solution :

This would do it:

^\[\d+(?:,\d+)*\]$
  • ^ – start line anchor
  • \[ – open literal square bracket
  • \d+ – one or more digits
  • (?: – open non-capturing group
    • ,\d+ – comma followed by one or more digits
  • ) – close non-capturing group
  • * – match pattern inside non-capturing group zero or more times
  • \] – close literal square bracket
  • $ – end line anchor

https://regex101.com/r/eVzjRw/1

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading