0

I'm pretty sure this is a dupe of a question from a couple weeks ago but I've been searching for about 15 minutes and I can't find it (somehow forgot to favorite it).

I want to prevent users from inputting their e-mail addresses or URLs into a text field. How can I automatically reject such submissions?

On the Plain text input filter, there is an option to Convert URLs into links, which also converts e-mail addresses into links. But what I want to do is remove all URLs, including e-mail addresses, that would be converted via this option. Is that possible?

3

The Field validation module let you set up your own regexp or PHP code to validate (or not) what user puts into a text field. However to reject e-mail addresses, your validator must be clever enough to not only recognize regular e-mail addresses such as spammer@example.com but also obfuscated e-mail adresses such as spammer(at)example.com.

Added note (about filtering): If, instead of rejecting input that do not validate, you want it filtered by having email addresses and links removed (or replaced with some string indicating redaction), you can use the Plain text input filter as a starting point, and just replace the code that currently turns email-adresses and URLs into live links, with code that redacts these things instead. Then, just rename the result of hacking the code, and add it to your configuration as a custom filter.

1
  • Thanks, but see my update about the Plain text input filter. I know users can use obfuscated e-mail addresses; in my case that's OK, I'm just worried about automated spam. Apr 30 '13 at 16:28
2

You can always create a module that defines its own filters. If you look in the core filters.module, _filter_url() is the bad boy that implements the Convert URLs into links filter, so I'd take that as a good starting point for the regexs need to obfuscate or remove the urls from the field in question. Then create a new input filter using your new filter instead of the stock ones and assign that to that field and you should be on your way.

Now, if you wanted to reject the node submission if any email address or urls were present anywhere in the field, then the Field validation module mentioned above/below is a great way to go.

2

I've been struggling with this problem too. My solution was to use Field validation module with custom PHP. Despite a lot of searching I only just came across your question. I have already documented the code I used over on the question I asked about this. I don't know whether it would be best 'Drupal Answers' practice to repeat the code here or not?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.