I need a regex for page sequences that
matches:
- 1
- 1, 4-5
- 1, 4-5, 8, 11, 13-14
but doesn't match:
- 1,,,,
- 1, 4-5-
- 1, 4--------2233-----,,,,
I have tried the following patterns but they don't work:
/^(\d*-\d*,?|\d*,?)*$/
/^(\d*-{1}\d*,?|\d*,?)*$/
I also want to validate user input while the user types, so the pattern needs to allow tailing - and , in certain cases. The example React code for allowing input with a particular pattern looks like this:
const customPageInputChange = (e) => {
if(e.target.value.match(/.../) !== null) {
setCustomPage(e.target.value)
}
}
See https://jsfiddle.net/mayankshukla5031/4zqwq1fj/ for a full example with input validation.