function extractEmails (text)
{
return text.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi);
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<input id="test" placeholder="start here">
<input placeholder="tab to here">
<script src="https://code.jquery.com/jquery-3.0.0.js"></script>
<script>
$(function(){
$('#test').on('blur',function(){
var testValue = $('#test').val();
alert(detect(testValue));
});
});
function detect(str){
if(str.includes("@")){
return "email";
} else {
return "phone";
}
}
</script>
</body>
</html>
The simple example may be
Open in new window
You may want to do additional validation though.