Constraint handling for @DataType (Typed Data API)
In abstract class PrimitiveBase that uses PrimitiveInterface... which StringData entends you can see the PrimitiveInterface use of PrimitiveInterface methods:

getValue(); , setValue($value);, getCastedValue();

so you can safely do ether however ... Personally as your data is realy a string  I would go with the extend StringData option 

and call 
parent functions like 

 public function getValue() {
   return parent::getValue();
   or 
   $this-&gt;parent-&gt;getValue();
 }

 public function setValue($value) {
    // CRAZY REGX HERE 
   $new_value = $this-&gt;getREGXCRAXY($value);

   return $this-&gt;parent-&gt;setValue($new_value);
 }

 public function  getREGXCRAXY($value) {
    do the things.
  if value !== valid 
 throw new \Exception('Invalid data dude must be in format xyz');
  return $new_formated_value; 
 }


no i think it is proper to throw the exception because then the person can catch it in an event subscriber .. or learn the right way to set the data.