I have a problem with regex and need your help. I want to check my string is correct or incorrect. First and last is a number, only number and comma after it. No space inside 2 numbers.
Ex:
- 1,2,3,49,5 this is correct
- 1,2,3,45, this is incorrect
- ,12,4,2,67 this is incorrect
- 1,2 3,4,5,6 this is incorrect
Please check below regex to solve your problem.
Regex:
^[0-9]+([0-9,])+[0-9]+$
^[0-9]+
is for start with one or more number[0-9]+$
is for end with one or more number([0-9,])+
is for one or more number with commaPlease check the output in Regex101
Update:
Please check the updated regex:
^(\d+,)+\d+$
^(\d+,)+
is for one or more number with comma and this will handle first number with comma\d+$
is for end with one or more numberPlease check the updated output in Regex101