0

I want to make sure that the email address entered by the user contains @ and . using RegExp.

This is my code:

var patt = new RegExp("@"); var pattresult = patt.test(document.getElementById("email").value); if (pattresult != true){ errMsg += "Enter a valid Email Address."; result = false; } 

Working fine so far only for @. How can I add . in the same pattern?

1 Answer 1

1

Try this, I have tested it.

var mail=document.getElementById("email").value; var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; if (!filter.test(mail) && mail!="") { alert('Enter a valid Email Address.') } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.