function check_entity_name_validity(name,div_id) { var check_regex = /$USERNAME_REGEX/; if (! check_regex.test(name) ) { document.getElementById(div_id).classList.add("has-error"); } else { document.getElementById(div_id).classList.remove("has-error"); } } EoCheckJS; } ###################################################### function render_js_username_generator($firstname_field_id,$lastname_field_id,$username_field_id,$username_div_id) { #Parameters are the IDs of the input fields and username name div in the account creation form. #The div will be set to warning if the username is invalid. global $USERNAME_FORMAT, $USERNAME_REGEX; render_js_username_check(); print << function update_username() { var first_name = document.getElementById('$firstname_field_id').value; var last_name = document.getElementById('$lastname_field_id').value; var template = '$USERNAME_FORMAT'; var actual_username = template; actual_username = actual_username.replace('{first_name}', first_name.toLowerCase() ); actual_username = actual_username.replace('{first_name_initial}', first_name.charAt(0).toLowerCase() ); actual_username = actual_username.replace('{last_name}', last_name.toLowerCase() ); actual_username = actual_username.replace('{last_name_initial}', last_name.charAt(0).toLowerCase() ); check_entity_name_validity(actual_username,'$username_div_id'); document.getElementById('$username_field_id').value = actual_username; } EoRenderJS; } ###################################################### function render_js_email_generator($username_field_id,$email_field_id) { global $EMAIL_DOMAIN; print << var auto_email_update = true; function update_email() { if ( auto_email_update == true && "$EMAIL_DOMAIN" != "" ) { var username = document.getElementById('$username_field_id').value; document.getElementById('$email_field_id').value = username + '@' + "$EMAIL_DOMAIN"; } } EoRenderEmailJS; } ?>