JavaScript regular [removed]Page range validation)

前端 未结 4 961
失恋的感觉
失恋的感觉 2020-12-19 19:21

Yesterday I\'ve got a task to implement a validation on the field where user can enter the range of pages that he wants to download.

After reading some tutorials, I

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-19 19:51

    You can try the regex:

    ^(\d+(-\d+)?)(,\d+(-\d+)?)*$
    

    To allow white spaces between you can do:

    ^(\s*\d+\s*(-\s*\d+\s*)?)(,\s*\d+\s*(-\s*\d+\s*)?)*$
    

    Rubular link

提交回复
热议问题