May 11, 2020 in Drupal 8

The routing system that drupal 8 offers is flexible in terms of validation. It is possible to validate your route against some typical regex lines. 

In the following mymodule.routing.yml yaml file, the {id} url parameter will be matched against the '\d+' regex, meaning a numeric character

/path/test/1 will be valid
/path/test/test will be 'page not found'

  path: '/path/{method}/{id}'
    _controller: '\Drupal\mymodule\Controller\mymoduleSaveController::Render'
    _title_callback: '\Drupal\mymodule\Controller\mymoduleSaveController::getTitle'
    _access: 'TRUE'
    id: '\d+'