0

Hi every one
my question is that i want to validate the form when any one wants to login or sign Up i want to check that the email address is correct or not means that email address include '@' char or not if not an error message should be displayed other wise not. i write the script but the problem is that it show alert message on each char, i want it will alert only one time here the script which i wrote.

for(var i = 0; i < email.length ; i++)
	{
		if(email.indexOf[i] == "@" )
		returnValue = true ;
		
		else
		{
			returnValue = false;
			alert("This is not a valid Email address, Please try again.")}
		}

waiting for your reply with script

3
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by Rizi004
0

The best way to validate e-mail address is with regular expression.

Here's the one I use:

// returns true or false
function isEmail(str)
{
	var regExp = /\b([\w-\.]+\@([\w-]+\.)+[\da-zA-Z]{2,4})\b/;
	regExp.test(str);
}

Hope it helps.

0

An easy way to check is using regular expression. Though it is not really a complete validation for email.

if (email.match(/@/)) { return true }

What you may want is to complete the regular expression for an email. However, it is difficult to create a really complete one nowadays.

Edit: You could use the whole regEx from Alemonteiro above post and replace in the match() function. However, remember that there can always be a way to break the rule and get it pass or fail with real/fake email address. One way to do is to split the incoming string into 2 parts - address and domain (address@domain) - using @ as delimiter. Then check each portion for proper patterns as you wish.

Edited by Taywin: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.