Click to See Complete Forum and Search --> : Trim


Laura81
January 20th, 2010, 08:35 AM
Hi there
I'm using search functionality on my website, to search for a customerid and customername.
I'm trying to make sure the customer enters the first three characters of each of the fields.


Could someone help me here?

My code so far is this:


m.merchantMID.ToLower().StartsWith(TextBox1.Text.ToLower().TrimStart()))

&&

m.merchantname.ToLower().StartsWith(TextBox2.Text.ToLower().TrimStart()) //


Thanks & Regards,
Lura

mariocatch
January 20th, 2010, 10:27 AM
Explain what you want to do in more detail please.

You have a search bar on your website.
They can search by customer ID or customer name?
You want to make sure they enter the first 3 characters before they can search?
Does this apply to customer ID? seems kinda weird...

You can just check the length of the Text property in the TextBox and see if it's >= 3?

boudino
January 21st, 2010, 02:21 AM
For simple check just use

string pattern = TextBox2.Text.ToLower().TrimStart();
if (pattern.Lenght >= 3)
{
m.merchantname.ToLower().StartsWith(pattern);
}


For more complex testing, you'll best use regular expressions, e.g.

Regex m.merchantname.Match(m.merchantname, "^" + TextBox2.Text.Trim(), RegexOptions.IgnoreCase);

nelo
January 21st, 2010, 04:00 AM
Hi boudino,

The use of the regular expression is nice. However why do you have to conver the text to lower case even though you've specified RegexOptions.IgnoreCase?

boudino
January 21st, 2010, 04:15 AM
Because of Ctrl+C, Ctrl+V ;)

... I've change it now.