|
-
January 20th, 2010, 09:35 AM
#1
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
-
January 20th, 2010, 11:27 AM
#2
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?
-
January 21st, 2010, 03:21 AM
#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);
Last edited by boudino; January 21st, 2010 at 05:16 AM.
- Make it run.
- Make it right.
- Make it fast.
Don't hesitate to rate my post. 
-
January 21st, 2010, 05:00 AM
#4
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?
-
January 21st, 2010, 05:15 AM
#5
Re: Trim
Because of Ctrl+C, Ctrl+V 
... I've change it now.
- Make it run.
- Make it right.
- Make it fast.
Don't hesitate to rate my post. 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|