email id domain check javascript 1

email id domain check javascript

var myemail = 'test@yahoo.com'

if (/@yahoo.com\s*$/.test(myemail)) {
   console.log("it ends in @yahoo");
} 

Here is what the above code is Doing:
1. The first line creates a variable called myemail and assigns it the value test@yahoo.com.
2. The second line creates a regular expression that looks for the string @yahoo.com followed by zero or more whitespace characters.
3. The third line uses the test() method to test whether the regular expression matches the string in the myemail variable.
4. The fourth line prints the string it ends in @yahoo to the console if the regular expression matches the string in the myemail variable.

Similar Posts