Skip to content

Instantly share code, notes, and snippets.

@salsalabs
Created November 19, 2015 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save salsalabs/de6bee05d98fdd7e4e16 to your computer and use it in GitHub Desktop.
Save salsalabs/de6bee05d98fdd7e4e16 to your computer and use it in GitHub Desktop.
Workaround to translate the "Please enter a valid emial address." message to German when "/l/ger/" is in the URL. Other languages can be done, too. Simply change the text for "/l/ger/" and the translated `message` variable.
<script type="text/javascript">
// SalsaStaff 114865: replace the email validation function with one
// that shows a mesage in German when the email address is invalid and
// the URL contains '/l/ger/'. The default is to show the standard
// Enlish message.
// Note: This script must appear *after* the teplate tags.
function validateEmail()
{
var email = $(this).attr('email');
if (email=="") return;
var re =/^[_a-zA-Z0-9!#$%&'*+/=?^`{|}~-]+(\.[_a-zA-Z0-9&'!#$%&'*+/=?^`{|}~-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*\.([a-zA-Z]{2,}){1}$/;
if (! re.test(email) ){
var message = 'Please enter a valid email address.';
if (window.location.href.indexOf('/l/ger/') !== -1) {
message = 'Bitte eine korrekte Email-Adresse eingeben.';
}
$("div[id='emailValidationErrorId']").html("<span class='required'>"
+ message
+ "</span>");
return false;
}else{
$("div[id='emailValidationErrorId']").html("");
return true;
};
}
$(document).ready(function() {
var e = $('input[name=Email]');
if (e.length == 0) return;
e.unbind('blur');
e.blur(validateEmail);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment