Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 10, 2012 10:41 AM by MS.NET10
Member
13 Points
26 Posts
Apr 09, 2012 10:37 PM|LINK
hi all,
This is velsamy , i have created a login Website using ASP.NET(C#) , what is the problem means, I have to prevent the special characters in the username textbox also i have tried a way like :
Code Behind:
protected void ValidateNoUrls(object sender, ServerValidateEventArgs e) { e.IsValid = !Regex.IsMatch(e.Value, @"(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&%\$#_]*)?"); }
aspx:
<asp:TextBox ID="TextBox1" runat="server" MaxLength="15" Width="220px" /> <asp:CustomValidator runat="server" OnServerValidate="ValidateNoUrls" ControlToValidate="TextBox1" ErrorMessage="Urls not allowed"/>
While i Triying this code there is a Compiler Error Message: CS0103: The name 'Regex' does not exist in the current context.
So anyone can help me,
Thanks in advance,
Velsamy A
Star
12528 Points
2024 Posts
Apr 09, 2012 11:01 PM|LINK
Do you have the following in your page?
using System.Text.RegularExpressions;
Alternatively, use the fully qualified typename System.Text.RegularExpressions.Regex
All-Star
97829 Points
14494 Posts
Apr 10, 2012 09:13 AM|LINK
Use RegularExpressionValidator...to validata against special chars..also if possible try to use MaskedEdit extender - http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/MaskedEdit/MaskedEdit.aspx
Thanks,
196 Points
55 Posts
Apr 10, 2012 10:41 AM|LINK
Hello Velsamy,
We can prevent user from entering 'extra' characters at CLIENT side by using AJAX extenders as below..
<pc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server" Enabled="True" TargetControlID="textboxID" ValidChars="0123456789."> </pc1:FilteredTextBoxExtender>
velsamy
Member
13 Points
26 Posts
ASP.NET login website creation
Apr 09, 2012 10:37 PM|LINK
hi all,
This is velsamy , i have created a login Website using ASP.NET(C#) , what is the problem means, I have to prevent the special characters in the username textbox also i have tried a way like :
Code Behind:
protected void ValidateNoUrls(object sender, ServerValidateEventArgs e)
{
e.IsValid = !Regex.IsMatch(e.Value, @"(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&%\$#_]*)?");
}
aspx:
<asp:TextBox ID="TextBox1" runat="server" MaxLength="15" Width="220px" />
<asp:CustomValidator runat="server" OnServerValidate="ValidateNoUrls" ControlToValidate="TextBox1" ErrorMessage="Urls not allowed"/>
While i Triying this code there is a Compiler Error Message: CS0103: The name 'Regex' does not exist in the current context.
So anyone can help me,
Thanks in advance,
Velsamy A
Prashant Kum...
Star
12528 Points
2024 Posts
Re: ASP.NET login website creation
Apr 09, 2012 11:01 PM|LINK
Do you have the following in your page?
using System.Text.RegularExpressions;
Alternatively, use the fully qualified typename System.Text.RegularExpressions.Regex
ramiramilu
All-Star
97829 Points
14494 Posts
Re: ASP.NET login website creation
Apr 10, 2012 09:13 AM|LINK
Use RegularExpressionValidator...to validata against special chars..also if possible try to use MaskedEdit extender - http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/MaskedEdit/MaskedEdit.aspx
Thanks,
JumpStart
MS.NET10
Member
196 Points
55 Posts
Re: ASP.NET login website creation
Apr 10, 2012 10:41 AM|LINK
Hello Velsamy,
We can prevent user from entering 'extra' characters at CLIENT side by using AJAX extenders as below..
<pc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server" Enabled="True" TargetControlID="textboxID" ValidChars="0123456789."> </pc1:FilteredTextBoxExtender>