How to validate textbox not to accept emailids
up vote
1
down vote
favorite
I have one field Company profile
: textbox
If the user enters any emailid in textbox,validation errormessage should display that user cant enter emailids in textbox.
i have tried the following code:
Regex regex = new Regex(@"^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$");
string values = commentstxt.Text.Trim().Split(' ');
for (int i = 0; i < values.Length; i++)
{
bool isValid = regex.IsMatch(values[i].ToString().Trim());
if (isValid)
{
//ScriptManager.RegisterStartupScript(this, this.GetType(), "CropImage", "alert('you can not enter email id.');", true);
//break;
Response.Write("<script language='javascript'>window.alert('you can not enter email id in company profile.');window.location='addlisting.aspx';</script>");
break;
}
else
{
Server.Transfer("addlistingpost.aspx", true);
}
}
If the user enters only test@gmail.com
,it gives the validation message saying you cannot enter emailid in the textbox which is correct and stays in the addlisting.aspx
page.
If the user enters say hello..how are you
,it redirects to the addlistingpost.aspx which is also correct.
The issue comes when user enters say hello test@gmail.com how are you
,it does not throw a validation message as emailid is present in the textbox.
I know here that it is only comparing values[0]
which is hello
and then directly goes into the else part.
How to achieve this?
Any help will be highly appreciated.
c# asp.net validation
add a comment |
up vote
1
down vote
favorite
I have one field Company profile
: textbox
If the user enters any emailid in textbox,validation errormessage should display that user cant enter emailids in textbox.
i have tried the following code:
Regex regex = new Regex(@"^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$");
string values = commentstxt.Text.Trim().Split(' ');
for (int i = 0; i < values.Length; i++)
{
bool isValid = regex.IsMatch(values[i].ToString().Trim());
if (isValid)
{
//ScriptManager.RegisterStartupScript(this, this.GetType(), "CropImage", "alert('you can not enter email id.');", true);
//break;
Response.Write("<script language='javascript'>window.alert('you can not enter email id in company profile.');window.location='addlisting.aspx';</script>");
break;
}
else
{
Server.Transfer("addlistingpost.aspx", true);
}
}
If the user enters only test@gmail.com
,it gives the validation message saying you cannot enter emailid in the textbox which is correct and stays in the addlisting.aspx
page.
If the user enters say hello..how are you
,it redirects to the addlistingpost.aspx which is also correct.
The issue comes when user enters say hello test@gmail.com how are you
,it does not throw a validation message as emailid is present in the textbox.
I know here that it is only comparing values[0]
which is hello
and then directly goes into the else part.
How to achieve this?
Any help will be highly appreciated.
c# asp.net validation
What is an "emailids"?
– Uwe Keim
Nov 21 at 9:52
Also, the regex you're using doesn't match the RFC 5322 spec for legal email addresses.
– Enigmativity
Nov 21 at 10:08
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have one field Company profile
: textbox
If the user enters any emailid in textbox,validation errormessage should display that user cant enter emailids in textbox.
i have tried the following code:
Regex regex = new Regex(@"^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$");
string values = commentstxt.Text.Trim().Split(' ');
for (int i = 0; i < values.Length; i++)
{
bool isValid = regex.IsMatch(values[i].ToString().Trim());
if (isValid)
{
//ScriptManager.RegisterStartupScript(this, this.GetType(), "CropImage", "alert('you can not enter email id.');", true);
//break;
Response.Write("<script language='javascript'>window.alert('you can not enter email id in company profile.');window.location='addlisting.aspx';</script>");
break;
}
else
{
Server.Transfer("addlistingpost.aspx", true);
}
}
If the user enters only test@gmail.com
,it gives the validation message saying you cannot enter emailid in the textbox which is correct and stays in the addlisting.aspx
page.
If the user enters say hello..how are you
,it redirects to the addlistingpost.aspx which is also correct.
The issue comes when user enters say hello test@gmail.com how are you
,it does not throw a validation message as emailid is present in the textbox.
I know here that it is only comparing values[0]
which is hello
and then directly goes into the else part.
How to achieve this?
Any help will be highly appreciated.
c# asp.net validation
I have one field Company profile
: textbox
If the user enters any emailid in textbox,validation errormessage should display that user cant enter emailids in textbox.
i have tried the following code:
Regex regex = new Regex(@"^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$");
string values = commentstxt.Text.Trim().Split(' ');
for (int i = 0; i < values.Length; i++)
{
bool isValid = regex.IsMatch(values[i].ToString().Trim());
if (isValid)
{
//ScriptManager.RegisterStartupScript(this, this.GetType(), "CropImage", "alert('you can not enter email id.');", true);
//break;
Response.Write("<script language='javascript'>window.alert('you can not enter email id in company profile.');window.location='addlisting.aspx';</script>");
break;
}
else
{
Server.Transfer("addlistingpost.aspx", true);
}
}
If the user enters only test@gmail.com
,it gives the validation message saying you cannot enter emailid in the textbox which is correct and stays in the addlisting.aspx
page.
If the user enters say hello..how are you
,it redirects to the addlistingpost.aspx which is also correct.
The issue comes when user enters say hello test@gmail.com how are you
,it does not throw a validation message as emailid is present in the textbox.
I know here that it is only comparing values[0]
which is hello
and then directly goes into the else part.
How to achieve this?
Any help will be highly appreciated.
c# asp.net validation
c# asp.net validation
edited Nov 21 at 9:53
Uwe Keim
27.3k30128210
27.3k30128210
asked Nov 21 at 9:37
chetan kambli
259110
259110
What is an "emailids"?
– Uwe Keim
Nov 21 at 9:52
Also, the regex you're using doesn't match the RFC 5322 spec for legal email addresses.
– Enigmativity
Nov 21 at 10:08
add a comment |
What is an "emailids"?
– Uwe Keim
Nov 21 at 9:52
Also, the regex you're using doesn't match the RFC 5322 spec for legal email addresses.
– Enigmativity
Nov 21 at 10:08
What is an "emailids"?
– Uwe Keim
Nov 21 at 9:52
What is an "emailids"?
– Uwe Keim
Nov 21 at 9:52
Also, the regex you're using doesn't match the RFC 5322 spec for legal email addresses.
– Enigmativity
Nov 21 at 10:08
Also, the regex you're using doesn't match the RFC 5322 spec for legal email addresses.
– Enigmativity
Nov 21 at 10:08
add a comment |
4 Answers
4
active
oldest
votes
up vote
1
down vote
accepted
You need to scan all the array till any error found. Kind of
Regex regex = new Regex( @"^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$");
string values = commentstxt.Text.Trim().Split(' ');
bool isValid = true; // valid word == not email
for (int i = 0; i < values.Length && isValid; i++)
{
bool isValid = !regex.IsMatch(values[i].ToString().Trim());
if (!isValid)
{
//ScriptManager.RegisterStartupScript(this, this.GetType(), "CropImage", "alert('you can not enter email id.');", true);
Response.Write("<script language='javascript'>window.alert('you can not enter email id in company profile.');window.location='addlisting.aspx';</script>");
}
}
if (isValid)
{
Server.Transfer("addlistingpost.aspx", true);
}
hi @Serg...Is it possible that i can use logical or part in Regex so that it also doesn't accept web address i.e. www.
– chetan kambli
Nov 21 at 10:31
add a comment |
up vote
2
down vote
The Regex that you're using is matching the start (^
) and the end ($
) of the string.
^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$
Just remove those characters to match anywhere within the line.
([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)
Try this code:
Regex regex = new Regex(@"([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)");
string text = "hello test@gmail.com how are you";
Console.WriteLine(regex.IsMatch(text));
It outputs True
.
Here's a regex, by the way, that nearly matches the RFC 5322 spec:
(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[x01-x08x0bx0cx0e-x1fx21x23-x5bx5d-x7f]|\[x01-x09x0bx0cx0e-x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[x01-x08x0bx0cx0e-x1fx21-x5ax53-x7f]|\[x01-x09x0bx0cx0e-x7f])+)])
add a comment |
up vote
1
down vote
Regex regex = new Regex(@"^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$");
string values = commentstxt.Text.Trim().Split(' ');
bool isValid = false;
for (int i = 0; i < values.Length; i++)
{
isValid = regex.IsMatch(values[i].ToString().Trim());
if (isValid)
{
//ScriptManager.RegisterStartupScript(this, this.GetType(), "CropImage", "alert('you can not enter email id.');", true);
//break;
Response.Write("<script language='javascript'>window.alert('you can not enter email id in company profile.');window.location='addlisting.aspx';</script>");
break;
}
else
{
continue;
}
}
if(!isValid)
{
Server.Transfer("addlistingpost.aspx", true);
}
add a comment |
up vote
1
down vote
Could you try something like this and see if that would work ? :
Regex regex = new Regex(@"^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$");
string values = commentstxt.Text.Trim().Split(' ');
bool hasEmail = false;
foreach (string str in values)
{
bool isCurrentValid = regex.IsMatch(str.Trim());
if (!isValid)
{
hasEmail = false;
} else {
hasEmail = true;
break;
}
}
if(hasEmail) {
Server.Transfer("addlistingpost.aspx", true);
}
else
{
Response.Write("<script language='javascript'>window.alert('you can not enter email id in company profile.');window.location='addlisting.aspx';</script>");
}
I basically left the logic of checking the whole string out of the loop.
add a comment |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
You need to scan all the array till any error found. Kind of
Regex regex = new Regex( @"^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$");
string values = commentstxt.Text.Trim().Split(' ');
bool isValid = true; // valid word == not email
for (int i = 0; i < values.Length && isValid; i++)
{
bool isValid = !regex.IsMatch(values[i].ToString().Trim());
if (!isValid)
{
//ScriptManager.RegisterStartupScript(this, this.GetType(), "CropImage", "alert('you can not enter email id.');", true);
Response.Write("<script language='javascript'>window.alert('you can not enter email id in company profile.');window.location='addlisting.aspx';</script>");
}
}
if (isValid)
{
Server.Transfer("addlistingpost.aspx", true);
}
hi @Serg...Is it possible that i can use logical or part in Regex so that it also doesn't accept web address i.e. www.
– chetan kambli
Nov 21 at 10:31
add a comment |
up vote
1
down vote
accepted
You need to scan all the array till any error found. Kind of
Regex regex = new Regex( @"^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$");
string values = commentstxt.Text.Trim().Split(' ');
bool isValid = true; // valid word == not email
for (int i = 0; i < values.Length && isValid; i++)
{
bool isValid = !regex.IsMatch(values[i].ToString().Trim());
if (!isValid)
{
//ScriptManager.RegisterStartupScript(this, this.GetType(), "CropImage", "alert('you can not enter email id.');", true);
Response.Write("<script language='javascript'>window.alert('you can not enter email id in company profile.');window.location='addlisting.aspx';</script>");
}
}
if (isValid)
{
Server.Transfer("addlistingpost.aspx", true);
}
hi @Serg...Is it possible that i can use logical or part in Regex so that it also doesn't accept web address i.e. www.
– chetan kambli
Nov 21 at 10:31
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
You need to scan all the array till any error found. Kind of
Regex regex = new Regex( @"^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$");
string values = commentstxt.Text.Trim().Split(' ');
bool isValid = true; // valid word == not email
for (int i = 0; i < values.Length && isValid; i++)
{
bool isValid = !regex.IsMatch(values[i].ToString().Trim());
if (!isValid)
{
//ScriptManager.RegisterStartupScript(this, this.GetType(), "CropImage", "alert('you can not enter email id.');", true);
Response.Write("<script language='javascript'>window.alert('you can not enter email id in company profile.');window.location='addlisting.aspx';</script>");
}
}
if (isValid)
{
Server.Transfer("addlistingpost.aspx", true);
}
You need to scan all the array till any error found. Kind of
Regex regex = new Regex( @"^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$");
string values = commentstxt.Text.Trim().Split(' ');
bool isValid = true; // valid word == not email
for (int i = 0; i < values.Length && isValid; i++)
{
bool isValid = !regex.IsMatch(values[i].ToString().Trim());
if (!isValid)
{
//ScriptManager.RegisterStartupScript(this, this.GetType(), "CropImage", "alert('you can not enter email id.');", true);
Response.Write("<script language='javascript'>window.alert('you can not enter email id in company profile.');window.location='addlisting.aspx';</script>");
}
}
if (isValid)
{
Server.Transfer("addlistingpost.aspx", true);
}
answered Nov 21 at 9:49
Serg
7,85821332
7,85821332
hi @Serg...Is it possible that i can use logical or part in Regex so that it also doesn't accept web address i.e. www.
– chetan kambli
Nov 21 at 10:31
add a comment |
hi @Serg...Is it possible that i can use logical or part in Regex so that it also doesn't accept web address i.e. www.
– chetan kambli
Nov 21 at 10:31
hi @Serg...Is it possible that i can use logical or part in Regex so that it also doesn't accept web address i.e. www.
– chetan kambli
Nov 21 at 10:31
hi @Serg...Is it possible that i can use logical or part in Regex so that it also doesn't accept web address i.e. www.
– chetan kambli
Nov 21 at 10:31
add a comment |
up vote
2
down vote
The Regex that you're using is matching the start (^
) and the end ($
) of the string.
^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$
Just remove those characters to match anywhere within the line.
([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)
Try this code:
Regex regex = new Regex(@"([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)");
string text = "hello test@gmail.com how are you";
Console.WriteLine(regex.IsMatch(text));
It outputs True
.
Here's a regex, by the way, that nearly matches the RFC 5322 spec:
(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[x01-x08x0bx0cx0e-x1fx21x23-x5bx5d-x7f]|\[x01-x09x0bx0cx0e-x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[x01-x08x0bx0cx0e-x1fx21-x5ax53-x7f]|\[x01-x09x0bx0cx0e-x7f])+)])
add a comment |
up vote
2
down vote
The Regex that you're using is matching the start (^
) and the end ($
) of the string.
^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$
Just remove those characters to match anywhere within the line.
([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)
Try this code:
Regex regex = new Regex(@"([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)");
string text = "hello test@gmail.com how are you";
Console.WriteLine(regex.IsMatch(text));
It outputs True
.
Here's a regex, by the way, that nearly matches the RFC 5322 spec:
(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[x01-x08x0bx0cx0e-x1fx21x23-x5bx5d-x7f]|\[x01-x09x0bx0cx0e-x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[x01-x08x0bx0cx0e-x1fx21-x5ax53-x7f]|\[x01-x09x0bx0cx0e-x7f])+)])
add a comment |
up vote
2
down vote
up vote
2
down vote
The Regex that you're using is matching the start (^
) and the end ($
) of the string.
^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$
Just remove those characters to match anywhere within the line.
([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)
Try this code:
Regex regex = new Regex(@"([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)");
string text = "hello test@gmail.com how are you";
Console.WriteLine(regex.IsMatch(text));
It outputs True
.
Here's a regex, by the way, that nearly matches the RFC 5322 spec:
(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[x01-x08x0bx0cx0e-x1fx21x23-x5bx5d-x7f]|\[x01-x09x0bx0cx0e-x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[x01-x08x0bx0cx0e-x1fx21-x5ax53-x7f]|\[x01-x09x0bx0cx0e-x7f])+)])
The Regex that you're using is matching the start (^
) and the end ($
) of the string.
^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$
Just remove those characters to match anywhere within the line.
([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)
Try this code:
Regex regex = new Regex(@"([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)");
string text = "hello test@gmail.com how are you";
Console.WriteLine(regex.IsMatch(text));
It outputs True
.
Here's a regex, by the way, that nearly matches the RFC 5322 spec:
(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[x01-x08x0bx0cx0e-x1fx21x23-x5bx5d-x7f]|\[x01-x09x0bx0cx0e-x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[x01-x08x0bx0cx0e-x1fx21-x5ax53-x7f]|\[x01-x09x0bx0cx0e-x7f])+)])
edited Nov 21 at 10:09
answered Nov 21 at 10:04
Enigmativity
74.6k764129
74.6k764129
add a comment |
add a comment |
up vote
1
down vote
Regex regex = new Regex(@"^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$");
string values = commentstxt.Text.Trim().Split(' ');
bool isValid = false;
for (int i = 0; i < values.Length; i++)
{
isValid = regex.IsMatch(values[i].ToString().Trim());
if (isValid)
{
//ScriptManager.RegisterStartupScript(this, this.GetType(), "CropImage", "alert('you can not enter email id.');", true);
//break;
Response.Write("<script language='javascript'>window.alert('you can not enter email id in company profile.');window.location='addlisting.aspx';</script>");
break;
}
else
{
continue;
}
}
if(!isValid)
{
Server.Transfer("addlistingpost.aspx", true);
}
add a comment |
up vote
1
down vote
Regex regex = new Regex(@"^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$");
string values = commentstxt.Text.Trim().Split(' ');
bool isValid = false;
for (int i = 0; i < values.Length; i++)
{
isValid = regex.IsMatch(values[i].ToString().Trim());
if (isValid)
{
//ScriptManager.RegisterStartupScript(this, this.GetType(), "CropImage", "alert('you can not enter email id.');", true);
//break;
Response.Write("<script language='javascript'>window.alert('you can not enter email id in company profile.');window.location='addlisting.aspx';</script>");
break;
}
else
{
continue;
}
}
if(!isValid)
{
Server.Transfer("addlistingpost.aspx", true);
}
add a comment |
up vote
1
down vote
up vote
1
down vote
Regex regex = new Regex(@"^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$");
string values = commentstxt.Text.Trim().Split(' ');
bool isValid = false;
for (int i = 0; i < values.Length; i++)
{
isValid = regex.IsMatch(values[i].ToString().Trim());
if (isValid)
{
//ScriptManager.RegisterStartupScript(this, this.GetType(), "CropImage", "alert('you can not enter email id.');", true);
//break;
Response.Write("<script language='javascript'>window.alert('you can not enter email id in company profile.');window.location='addlisting.aspx';</script>");
break;
}
else
{
continue;
}
}
if(!isValid)
{
Server.Transfer("addlistingpost.aspx", true);
}
Regex regex = new Regex(@"^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$");
string values = commentstxt.Text.Trim().Split(' ');
bool isValid = false;
for (int i = 0; i < values.Length; i++)
{
isValid = regex.IsMatch(values[i].ToString().Trim());
if (isValid)
{
//ScriptManager.RegisterStartupScript(this, this.GetType(), "CropImage", "alert('you can not enter email id.');", true);
//break;
Response.Write("<script language='javascript'>window.alert('you can not enter email id in company profile.');window.location='addlisting.aspx';</script>");
break;
}
else
{
continue;
}
}
if(!isValid)
{
Server.Transfer("addlistingpost.aspx", true);
}
answered Nov 21 at 9:51
Sagar Shirke
581721
581721
add a comment |
add a comment |
up vote
1
down vote
Could you try something like this and see if that would work ? :
Regex regex = new Regex(@"^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$");
string values = commentstxt.Text.Trim().Split(' ');
bool hasEmail = false;
foreach (string str in values)
{
bool isCurrentValid = regex.IsMatch(str.Trim());
if (!isValid)
{
hasEmail = false;
} else {
hasEmail = true;
break;
}
}
if(hasEmail) {
Server.Transfer("addlistingpost.aspx", true);
}
else
{
Response.Write("<script language='javascript'>window.alert('you can not enter email id in company profile.');window.location='addlisting.aspx';</script>");
}
I basically left the logic of checking the whole string out of the loop.
add a comment |
up vote
1
down vote
Could you try something like this and see if that would work ? :
Regex regex = new Regex(@"^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$");
string values = commentstxt.Text.Trim().Split(' ');
bool hasEmail = false;
foreach (string str in values)
{
bool isCurrentValid = regex.IsMatch(str.Trim());
if (!isValid)
{
hasEmail = false;
} else {
hasEmail = true;
break;
}
}
if(hasEmail) {
Server.Transfer("addlistingpost.aspx", true);
}
else
{
Response.Write("<script language='javascript'>window.alert('you can not enter email id in company profile.');window.location='addlisting.aspx';</script>");
}
I basically left the logic of checking the whole string out of the loop.
add a comment |
up vote
1
down vote
up vote
1
down vote
Could you try something like this and see if that would work ? :
Regex regex = new Regex(@"^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$");
string values = commentstxt.Text.Trim().Split(' ');
bool hasEmail = false;
foreach (string str in values)
{
bool isCurrentValid = regex.IsMatch(str.Trim());
if (!isValid)
{
hasEmail = false;
} else {
hasEmail = true;
break;
}
}
if(hasEmail) {
Server.Transfer("addlistingpost.aspx", true);
}
else
{
Response.Write("<script language='javascript'>window.alert('you can not enter email id in company profile.');window.location='addlisting.aspx';</script>");
}
I basically left the logic of checking the whole string out of the loop.
Could you try something like this and see if that would work ? :
Regex regex = new Regex(@"^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$");
string values = commentstxt.Text.Trim().Split(' ');
bool hasEmail = false;
foreach (string str in values)
{
bool isCurrentValid = regex.IsMatch(str.Trim());
if (!isValid)
{
hasEmail = false;
} else {
hasEmail = true;
break;
}
}
if(hasEmail) {
Server.Transfer("addlistingpost.aspx", true);
}
else
{
Response.Write("<script language='javascript'>window.alert('you can not enter email id in company profile.');window.location='addlisting.aspx';</script>");
}
I basically left the logic of checking the whole string out of the loop.
answered Nov 21 at 9:52
Sk83r1l4m4
478
478
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409070%2fhow-to-validate-textbox-not-to-accept-emailids%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What is an "emailids"?
– Uwe Keim
Nov 21 at 9:52
Also, the regex you're using doesn't match the RFC 5322 spec for legal email addresses.
– Enigmativity
Nov 21 at 10:08