Hello All,

I'm looking for a module that will allow me to specify allowed characters for text fields in content types.

For example: I have a Purchase Order content type, and one of the fields contains a list of customer names the order is for. Trying to get people to follow simple rules is impossible. I just want them to type in a name in the format "J. Smith", but they want to use other characters instead, like "Smith///j. Doe///etc". Which messes up searching and text wrapping if there are a lot of names. I want to be able to allow only a-z, A-Z, 0-9, and ",." Nothing more.

Been searching Drupal for 30 minutes, and the only thing close I can see is the Masked Input module, which won't work for me. I don't want a mask, I want a whitelist of characters that are allowed.

Thanks!

Comments

sprite’s picture

Try the following module:

https://www.drupal.org/project/field_validation

You will need to delve into the wacky world of regular expressions to use it to the fullest.
There are however books in regex and plenty of "regular expression recipes" available via google searches.

http://php.net/manual/en/reference.pcre.pattern.syntax.php

Example:

The following regular expression limits inserted data to unicode alpha characters:

/\A[[:alpha:]]+\z/i

-----
The following module is specifically for validating usernames at registration and during user profile editing.

https://www.drupal.org/project/custom_username_validation

This module needs a small one line modification as I have explained at the following article:

https://www.drupal.org/node/1823428

spritefully yours
Technical assistance provided to the Drupal community on my own time ...
Thank yous appreciated ...

Steel Rat’s picture

Wacky world is right, lol. I've been exposed to RegEx for decades, but never got intimate.

Many thanks for your suggestions. I think the field_validation module will do what I need.

Thanks Sprite!

sprite’s picture

I most often use Google search to find modules, not the modules exploration page on drupal.org.
However, it can be useful to spend an evening simply browsing the drupal.org modules search facility and downloading interesting modules to a drupal/modules/8x/ directory for later study and use.

Try the following query style for Google Search to hunt for modules

{such as such interest} module site:drupal.org

For example:

"field validation module site:drupal.org"

https://www.google.com/search?q=field+validation+module+site%3Adrupal.org

Yields multiple interesting results, projects and articles, including:

https://www.drupal.org/project/webform_validation

https://www.drupal.org/project/clientside_validation

https://www.drupal.org/project/unique_field
(check out the module above for an important feature you may want)

Three additional important and relevant modules

spritefully yours
Technical assistance provided to the Drupal community on my own time ...
Thank yous appreciated ...