Filter a field (with regex) in a view I have a view with a field Title that needs to be filtered before being sent:


Users fill a tracking number and press Enter
This number is actually related to a node id
If a user enter "123 123" or "#123123" it will not work because of the space and/or the # symbol


My first guess as a non-expert in Drupal (and coming from other CMS and PHP Framework) would be to add a filter to this input with a regex on it to get rid of all characters that are not 1-9. However, I tried to accomplish such a thing in creating a Filter Critera but it does not seem to be the solution.

Do you have any recommendation to do such a thing?

Thanks
"Filters" have certain meaning in Views. They are this little things that give "go" or "no-go" to result rows. What you seems to want is to rewrite user's input, not filter.

hook_form_alter I see in your tags is actually a good call. You can use it to append AJAX to onblur and make it rewrite field. Or you can use validation function

function yourmodule_form_validate($form, &amp;$form_state) {
  $form_state['input']['yourfield'] = _mymodule_sanitize( $form_state['input']['yourfield'] );
}


to rewrite it after user's submit, but before it is used by views. This function takes &amp;$form_state by reference. It means you are allowed not only to read it, but also write to it, and your changes will be visible for all submit functions attached to your form, and will be used in next rendering of your form in case of validation errors or multis-tep forms.