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
-
You can check all error messages in root/lib/web/mage/validation.jsPrince Patel– Prince Patel2017年06月06日 05:31:52 +00:00Commented Jun 6, 2017 at 5:31
2 Answers 2
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>
-
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.Vinit Kumar– Vinit Kumar2019年12月20日 13:57:55 +00:00Commented Dec 20, 2019 at 13:57
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