Validate Email – Regular Expression & Test Function Cognizant Handson
Write a JavaScript program to validate an email id using Regular Expression.
The function validateEmail must take an email string as its argument and return one of the following 2 statements: Valid email address! – when found valid & Invalid email address! – when found invalid
script.js
function validateEmail(email) {
var result = (/^\w+([\.-]?\w+)@\w+([\.-]?\w+)(\.\w{2,3})+$/).test(email)
if(result===true){
return "Valid email address!"
}
else{
return "Invalid email address!"
}
}
