I'm very new in Drupal, I would like to restrict some special characters from user password field Is there any way to edit configuration of core modules i'm trying to create preg_match modules . i would like to allow only these character in password fields.

preg_match('/[^ A-Za-z 0-9 ,.-()]/'), $edit-pass-pass1

Don't re-invent the wheel if these will solve your needs and hopefully wants.


also worth looking into https://www.drupal.org/project/password_strength

If those don't work, I think you're looking at a form alter related to validation. Drupal 8 is the wonderful world of Form Alters... so look into those even if the above solves your needs.

  • you are right using this modules i can solve this issues but i would not like to use these modules. How could i alter filed validation for core modules my requirement is allow in password filed A-Za-z 0-9 ,.-()please guide me – Shyam Jun 11 at 12:01
  • i have try this modules but password encryption is not working, so i'm thinking i could alter only password field – Shyam Jun 12 at 12:16

Read you comments on my other answer. Here's how I would start tackling in your situation. I think you're going down a Form Alter method. Start off simple. Create a new module with just an .info and .module. In the .module, add code to find what you're looking for. KSM will show you the array and you can dig in.

 * Implements form_alter().
 * form_id : node_check_in_form 
function yourmodulename_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  switch ($form_id) {
    //turn off the ability to edit 'type' after creation per spec
    case 'yourcasehere':

Basically, figure out your form name. Then see what the form is. You can alter the form to have new validation.


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.