You need to make use of the validation property of the widget property which gets passed to your component.
See this link: https://docs.mendix.com/apidocs-mxsdk/apidocs/pluggable-widgets-client-apis-9/#editable-value