3

I have been doing some user testing and noticed that lots of people put in a space after their email address i.e. "name@domain.com "

Error message

Magento shows a red box error on it, but some users get confused and don't know what to do. Is there a easy way of trimming the space from the email, through either code or javascript?

6

Add the below script in any of your js file.

Validation.add('validate-email', 'Please enter a valid email address. For example johndoe@domain.com.', function(v) {
    var emailInput = v.trim();
    return Validation.get('IsEmpty').test(emailInput) || /^([a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*@([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*\.(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]){2,})$/i.test(emailInput);
})

Note : Above code will not work on RWD theme, because they have used html5 attribute type="email" to the input field.

| improve this answer | |
2

first check what JS your checkout is using. u can use the google cmd+alt+I (i am using mac)

then see what JS are beeing used.

the past

Validation.add('validate-email', 'Please enter a valid email address. For example johndoe@domain.com.', function(v) {
    var emailInput = v.trim();
    return Validation.get('IsEmpty').test(emailInput) || /^([a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*@([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*\.(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]){2,})$/i.test(emailInput);
});
| improve this answer | |
1

This will remove all blank spaces before magento form validation

$(':input').change(function() {
    $(this).val($(this).val().trim());
});
| improve this answer | |

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.