Validating a tridion TCM ID using Regex on javascript, looks quiet simple but unfortunately I failed to do this.
I have attempted all the possible ways to validate a tcm id.
Below is the last tried regex:-
(tcm:(\d)+-(\d)+(-16|-4|-64))\W
Here, TCM ID
can be component
or SG
or Page
.
Valid tcm id's are
Please suggest the best regex to validate a tcm id.
The regex xdazz provided is great for matching the examples you gave. But for more generic handling you might want to:
/^tcm:\d+-\d+(?:-16|-4|-64)?$/
/^tcm:\d+-\d+(?:-\d+)?$/
/^tcm:\d+-\d+(?:-\d+)?(?:-v\d+)?$/
Of course that brings you pretty close to Nuno's answer, which has the added advantage that the match groups have readable names.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With