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

Regexp for <input> tag

I need restict values for input tag by next values :

1
1,2,3
!2,!3
[1-2]
[1-4],[3-5]
![1-4],![3-5]
1,2,3,[1-4],[3-5]
![1-4],![3-5],1,2,!7

1,2,3..7 are just examples, it may be any digits

My pattern is :

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

<input type="text"  pattern="(\d*|[\d\-\d,]*|[\!\d]*|[|\[\d-\d\],]*|[\!\[\d\-\d\],]*)"/>

But this is also acceptable:

!!!!!![10-121,444--------,,,,,!!!!----------------,----------]

>Solution :

It looks like you’re looking for a sequence of items that are either a number or a range, both possibly preceded by an exclamation mark.

A single item can be represented as follows :

!?(\d|\[\d-\d\])

A sequence of such items is the item, followed by any number of a comma and another occurence of the item, which can be represented as follows :

!?(\d|\[\d-\d\])(,!?(\d|\[\d-\d\]))*

You can try it here.

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