diff --git a/container_app_conf/entry/string.py b/container_app_conf/entry/string.py
index ce12615..e2d2a6a 100644
--- a/container_app_conf/entry/string.py
+++ b/container_app_conf/entry/string.py
@@ -17,6 +17,7 @@
 #  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 #  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 #  SOFTWARE.
+import re
 
 from container_app_conf import ConfigEntry
 
@@ -24,6 +25,11 @@ from container_app_conf import ConfigEntry
 class StringConfigEntry(ConfigEntry):
     _example = "text"
 
+    def __init__(self, key_path: [str], example: any = None, description: str or None = None, default: any = None,
+                 none_allowed: bool = None, regex: str = None):
+        self.regex = re.compile(regex) if regex is not None else None
+        super().__init__(key_path, example, description, default, none_allowed)
+
     def _value_to_type(self, value: any) -> str or None:
         """
         Converts the given type to the expected type
@@ -35,4 +41,8 @@ class StringConfigEntry(ConfigEntry):
             if s.lower() in ['none', 'null', 'nil']:
                 return None
 
+        if self.regex is not None:
+            if not self.regex.match(s):
+                self._raise_invalid_value(s)
+
         return s

Restrict valid input of StringConfigEntry using regex
As the title states.
diff --git a/tests/entry_test.py b/tests/entry_test.py
index 80c6a8c..ab36331 100644
--- a/tests/entry_test.py
+++ b/tests/entry_test.py
@@ -48,6 +48,17 @@ class EntryTest(EntryTestBase):
 
         self.assert_input_output(config_entry, input_output)
 
+    def test_string_entry_regex(self):
+        config_entry = StringConfigEntry(key_path=["string"], none_allowed=True, regex="^[0-9]*$")
+
+        input_output = [
+            ("5", "5"),
+            ("hello", ValueError),
+            ("$stuff=)(&/%$§", ValueError),
+        ]
+
+        self.assert_input_output(config_entry, input_output)
+
     def test_regex_entry(self):
         config_entry = RegexConfigEntry(key_path=["regex"], none_allowed=True)
 

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest
apt-get update apt-get install -y gcc
3.7
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
certifi @ file:///croot/certifi_1671487769961/work/certifi
-e git+https://github.com/markusressel/container-app-conf.git@64e0448c5a66680391958a2f1ff2b76de255ac2c#egg=container_app_conf
exceptiongroup==1.2.2
importlib-metadata==6.7.0
iniconfig==2.0.0
packaging==24.0
pluggy==1.2.0
py-range-parse==1.0.5
pytest==7.4.4
python-dateutil==2.9.0.post0
pytimeparse==1.1.8
PyYAML==6.0.1
six==1.17.0
toml==0.10.2
tomli==2.0.1
typing_extensions==4.7.1
zipp==3.15.0

name: container-app-conf
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2022.12.7=py37h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=22.3.1=py37h06a4308_0
  - python=3.7.16=h7a1cb2a_0
  - readline=8.2=h5eee18b_0
  - setuptools=65.6.3=py37h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.38.4=py37h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - exceptiongroup==1.2.2
      - importlib-metadata==6.7.0
      - iniconfig==2.0.0
      - packaging==24.0
      - pluggy==1.2.0
      - py-range-parse==1.0.5
      - pytest==7.4.4
      - python-dateutil==2.9.0.post0
      - pytimeparse==1.1.8
      - pyyaml==6.0.1
      - six==1.17.0
      - toml==0.10.2
      - tomli==2.0.1
      - typing-extensions==4.7.1
      - zipp==3.15.0
prefix: /opt/conda/envs/container-app-conf

tests/entry_test.py::EntryTest::test_string_entry_regex
tests/entry_test.py::EntryTest::test_bool_entry tests/entry_test.py::EntryTest::test_date_entry tests/entry_test.py::EntryTest::test_directory_entry tests/entry_test.py::EntryTest::test_file_entry tests/entry_test.py::EntryTest::test_float_entry tests/entry_test.py::EntryTest::test_int_entry tests/entry_test.py::EntryTest::test_range_entry tests/entry_test.py::EntryTest::test_regex_entry tests/entry_test.py::EntryTest::test_string_entry tests/entry_test.py::EntryTest::test_timedelta_entry
container_app_conf/entry/string.py
container_app_conf/entry/string.py