1

In Magento 2 How to change Sign up Error message

I want to change this Minimum of different classes of characters in password is 3. Classes of characters: Lower Case, Upper Case, Digits, Special Characters. Where i need to change this error message

enter image description here

asked Jun 5, 2017 at 16:12
1
  • You can check all error messages in root/lib/web/mage/validation.js Commented Jun 6, 2017 at 5:31

2 Answers 2

1

I found this solution and it worked for me. Add data-validate='{"telephone-check-maximum-length-15":true}' in your input tag. And add below javascript at the end of your phtml file.

<script type="text/javascript">
require([
 'jquery', // jquery Library
 'jquery/ui', // Jquery UI Library
 'jquery/validate', // Jquery Validation Library
 'mage/translate' // Magento text translate (Validation message translte as per language)
], function($){ 
 $.validator.addMethod(
 'telephone-check-maximum-length-15', function (value) {
 return (value.length<15); // Validation logic here
 },
 $.mage.__('Please enter less or equal than 15 digits.')
 );
});
</script>
answered Sep 26, 2018 at 11:18
1
  • Hello Kazim I have to change the error div position in footer newsletter " footer_newsletter " subscription to top of the input box, can you suggest me how can i do it . "footer_newsletter-error" is new dynamically appends to input box. Commented Dec 20, 2019 at 13:57
3

Here is the solution which worked for me to changing the message of password field. It might help you in your direction.I have created script rather than overriding entire validation.js. I have added new function and replace error with new. As magento2 is using jquery validation. I have taken this function from validation.js

require([
 'jquery',
 'jquery/ui',
 'jquery/validate',
 'mage/translate'
 ], function($){
 $('#password').attr('data-validate', $('#password').attr('data-validate').replace('validate-customer-password','validate-customer-password-custom'));
 $.validator.addMethod(
 'validate-customer-password-custom', function(v, elm) {
 var validator = this,
 length = 0,
 counter = 0;
 var passwordMinLength = $(elm).data('password-min-length');
 var passwordMinCharacterSets = $(elm).data('password-min-character-sets');
 var pass = $.trim(v);
 var result = pass.length >= passwordMinLength;
 if (result == false) {
 validator.passwordErrorMessage = $.mage.__(
 "Minimum length of this field must be equal or greater than %1 symbols." +
 " Leading and trailing spaces will be ignored."
 ).replace('%1', passwordMinLength);
 return result;
 }
 if (pass.match(/\d+/)) {
 counter ++;
 }
 if (pass.match(/[a-z]+/)) {
 counter ++;
 }
 if (pass.match(/[A-Z]+/)) {
 counter ++;
 }
 if (pass.match(/[^a-zA-Z0-9]+/)) {
 counter ++;
 }
 if (counter < passwordMinCharacterSets) {
 result = false;
 validator.passwordErrorMessage = $.mage.__(
 "Minimum of different classes of characters in password is %1." +
 " Classes of characters: Lower Case, Upper Case, Digits, Special Characters."
 ).replace('%1', passwordMinCharacterSets);
 }
 return result;
 }, function () {
 return this.passwordErrorMessage;
 });
 });

Here is more detail about this solution on my own blog and entire module for this on my Github repository

answered Jun 11, 2017 at 11:43
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.