Problem statement
Write an anonymous function which take email address as parameter and returns true/false after validating the input parameter.
Objective
This assignment will help you to master the following concepts:
function
closures
Solution
<!DOCTYPE html>
<html>
<head>
<title>Anomymous function</title>
<meta charset="UTF-8">
<script type="text/javascript">
var result = (function(email_id){
var regpat = /^[a-zA-Z_\.\-]+@[a-zA-Z_\-\.]+?\.[a-zA-Z]{2,4}$/;
return regpat.test(email_id);
})('[email protected]');
document.write(result);
</script>
</head>
<body>
</body>
</html>
1) Is this the corresponding solution?
2) Why document.body.innerHTML = result;
does not work?