0

there is a huge issue where when a Phone number field is validated on a webform, we get the following error message:

North American Phone numbers should only contain numbers and + and - and ( and ) and spaces and be like 999-999-9999. Please enter a valid ten-digit phone number with optional extension.

In reality we need an ability to customize this and we were looking into the hook_form_alter, but we hit a snag and cannot find ways to modify the error message. How would we be able to modify the validation messages?

0

One solution here is the String Overrides module.

Provides a quick and easy way to replace any text on the site.

Features

  • Easily replace anything that's passed through t()
  • Locale support, allowing you to override strings in any language
  • Ability to import/export *.po files, for easy migration from the Locale module
  • Note that this is not a replacement to Locale as having thousands of overrides can cause more pain then benefit. Use this only if you need a few easy text changes.

For your case, you can override the Phone module's default error message. By placing this string in this string:

"%value" is not a valid North American phone number
North American Phone numbers should only contain numbers and + and - and ( and ) and spaces and be like 999-999-9999. Please enter a valid ten-digit phone number with optional extension.

And substituting whatever you need it to display.

  • One solution we found is to patch the phone module as we found the validation message coming from that module. – sf_admin819 Aug 10 '16 at 17:38

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.