String Comparison
I have one text box. If anybody enters value like <,>,create,drop etc,The error message will come.
I need To avoid that.Also My Visual studio software does not support Valiation controls like regular expression validtor,required field validatr etc,So I cant use regular expression validatior to avoid this sql injection
B'coz of this reason I decide to use string comparison to check the textbox value charrecter by charrecter . so I can find out the illegal symbols which entered in the text box.
Then I can display the error message...
Can anybody help me???

Kirtan PatelRank #292 · 8.6K reputationPosted Aug 29, 2009, 4:13 AM EDT
tell me for what purpose you need regex ?
Sibin AA19 reputationPosted Aug 29, 2009, 2:46 AM EDT
Kirtan PatelRank #292 · 8.6K reputationPosted Aug 29, 2009, 2:56 AM EDT
you can do this without validator control using RegEx
take a Look at following code .
dont forget to mark "Do you like answer" please if answer helped you .:)
here you dont have to check only if user enters any symbols in TextBox For Preventing SQL Injection you dont have to filter all those create etc words :)
protected void Button1_Click(object sender, EventArgs e)
{
string TextToValidate = TextBox1.Text.Trim();
Regex re = new Regex("^[a-zA-Z0-9 ]*$");
if (re.IsMatch(TextToValidate) == false )
{
Page.RegisterClientScriptBlock("", "");
}
}
Sibin AA19 reputationPosted Aug 29, 2009, 3:05 AM EDT
Kirtan PatelRank #292 · 8.6K reputationPosted Aug 29, 2009, 3:18 AM EDT
using System.Text.RegularExpressions;
at the top of the code Write above it will not show error now. :)
Happy Coding:)
Sibin AA19 reputationPosted Aug 29, 2009, 3:58 AM EDT
Sibin AA19 reputationPosted Aug 30, 2009, 9:42 PM EDT
etc... the error will come....... I need the REgex which satisfy only numbers and letters... If any other Symbols comes anywhere in the text box ,then the regex never stisfy... please help me.....
Kirtan PatelRank #292 · 8.6K reputationPosted Aug 31, 2009, 3:35 AM EDT
the code above i given to you is for that purpose
it will not allow any symbols
it will only allow only numbers and Alphabets
protected void Button1_Click(object sender, EventArgs e)
{
string TextToValidate = TextBox1.Text.Trim();
Regex re = new Regex("^[a-zA-Z0-9 ]*$");
if (re.IsMatch(TextToValidate) == false )
{
Page.RegisterClientScriptBlock("", "");
}
}
Sibin AA19 reputationPosted Sep 3, 2009, 9:46 PM EDT