This is exactly the same issue as
how to split numbers using substring[
^], which I already answered. If you want to verify parts of the content as it is entered then you should not make assumptions about the length of substrings, or where they occur. In the above case if the user enters:
foo(01)abc(21)bar
your code will crash, because you are trying to extract a substring beyond the limit of the entered data.