Validate Email - Regular Expression & test Function
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
Note: Refer to the function arguments within the given console.log to create a regex pattern for valid email address. You may verify the correctness of your function by invoking it from within console.log
ANSWER:
script.js
function validateEmail(email) {
//fill the code
if(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/i.test(email)){
return "Valid email address!";
}
else{
return "Invalid email address!"
}
}
No comments:
Post a Comment