You can use this regex in preg_match
to validate your input:
'/\[\d+(,\d+)*\]/'
\[ matches the character [ literally
\d+ match a digit [0-9]
Quantifier: Between one and unlimited times, as many times as possible, giving back as
needed [greedy]
1st Capturing group (,\d+)*
Quantifier: Between zero and unlimited times, as many times as possible, giving back as
needed [greedy]
Note: A repeated capturing group will only capture the last iteration. Put a capturing
group around the repeated group to capture all iterations or use a non-capturing group
instead if you're not interested in the data
, matches the character , literally
\d+ match a digit [0-9]
Quantifier: Between one and unlimited times, as many times as possible, giving back as
needed [greedy]
\] matches the character ] literally