Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)

I was trying to validate an email address whenever user have entered one. I have tried with the below code, but it is not working:

 function check(email) {

            var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

            //var address = document.getElementById[email].value;

            if (reg.test(email) == false) 

            {

                alert('Invalid Email Address');

                return (false);

            }

 }

Can anyone help me how I can able to solve this issue?

1 Answer

0 votes
by (26.7k points)

Basically, the code for the regex is correct, but you need to add the following line in your TextField:

<input type="text" onblur="validateEmail(this);" />

I hope this will help.

Want to know more about Java? Prefer this tutorial on Learn Java.

Want to become a Java expert? join Java Certification now!!

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...