Along with JohnAtl’s regex, you should be able to use the “Match Text” action in Shortcuts to validate the input. Then you can use the “If” action to test that the input contains the “Text Matches” magic variable.
Does that capture what you’re trying to accomplish?