-
Trim
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
-
Re: Trim
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?
-
Re: Trim
For simple check just use
Code:
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.
Code:
Regex m.merchantname.Match(m.merchantname, "^" + TextBox2.Text.Trim(), RegexOptions.IgnoreCase);
-
Re: Trim
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?
-
Re: Trim
Because of Ctrl+C, Ctrl+V ;)
... I've change it now.