i want to create a form that extracts email addresses from input text ,
i know there is a lot of scripts which do this easily , but i want to create one by myself .
So i read , searched and tried but i couldn't see a result . here is my code , what is the problem ?
<html>
<head>
<script type="text/javascript">
function extractEmails ( text ){
return text.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi);
}
// EXAMPLE #1
var emails = extractEmails ( HugeListWithBulkTextIncludingEmailAddresses );
document.write ( emails.join('\n') );
// EXAMPLE #2 (jQuery)
$(function(){
$('#eform').submit(function(){
$('#extractedemails').val( extractEmails($('#input').val() ).join('\n'));
return false;
});
});
</script>
</head>
<body>
<form name="myform" id="eform" action="javascript:extractEmails()">
<input type="text" name="firstname">
<input name="Submit" type="submit" value="Update"/>
</form>
<textarea id="extractedemails">
</textarea>
</body>
</html>
idofinput. Also, using javascript in theactionattribute is not widely supported, attach your code to thesubmitevent instead.