The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group

Slack Signup
Newsletter Optin
Help Desk

javascript username extract from email address

Labels

This Discussion is public

Notifications

Hello,

I need to extract the part before @ from email address.
For example:
Field-1 (e-mail): [email protected]
Field-2 (copy from the e-mail): example

I used the following code;

<script type="text/javascript">
jQuery(document).ready(function($){
$('#field_source').change(function(){ //source field key
var sourceField = $("#field_source").val(); //source field key
$("#field_dest").val(sourceField); //destination field key
$("#field_dest").change(); //destination field key
});
});
</script>

But, it copies whole e-mail address.

So, i would like to add the following code the work it.

var name = email.substring(0, email.indexOf("@"));

How to make the complete code?

Please help.

Thanks.

https://jsfiddle.net/1hdvx1y8/3/

I'm using the focusout method, such that function doesn't execute until you leave the input box.

GREAT~ Thanks.

Discussion closed.