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 PatelPosted Aug 29, 2009, 8:13 AM
tell me for what purpose you need regex ?
Sibin AAPosted Sep 4, 2009, 1:46 AM
Kirtan PatelPosted Aug 31, 2009, 7:35 AM
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 AAPosted Aug 31, 2009, 1:42 AM
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.....
Sibin AAPosted Aug 29, 2009, 7:58 AM
Kirtan PatelPosted Aug 29, 2009, 7:18 AM
using System.Text.RegularExpressions;
at the top of the code Write above it will not show error now. :)
Happy Coding:)
Sibin AAPosted Aug 29, 2009, 7:05 AM
Kirtan PatelPosted Aug 29, 2009, 6:56 AM
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 AAPosted Aug 29, 2009, 6:46 AM