var email = "john-smith@hotmail.co.uk"
var parts = email.split("@"); // Splits the email at the @ symbol
var username = parts[0]; // Can be used as a username if you'd like, but we'll use it to find names anyway
var delimiters = [".", "-", "_"]; // List of common email name delimiters, feel free to add to it
delimiters.forEach(splitting_loop);
function splitting_loop(element, index, array) { // Checks all the delimiters
var num = username.indexOf(element); // Gets the position of the delimter
if (num > -1) { // If there is a delimiter
fname = username.substring(0, (num)); // Gets data before delimiter
lname = username.substring(num + 1, (username.length)); // Gets name after delimiter
fname = fname.toLowerCase(); // Makes it all lower case
lname = lname.toLowerCase();
fname = fname.charAt(0).toUpperCase() + fname.slice(1); // Lets make the first letter upper case as well so it looks prettier
lname = lname.charAt(0).toUpperCase() + lname.slice(1);
}
}
if (typeof fname !== 'undefined') { // If we've found a delimiter we can use it
window.alert(fname);
window.alert(lname);
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.