Click here to Skip to main content
15,908,013 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
if textbox1 contains string if any 4 or more continuous character from textbox1 are matches with string in textbox2 then wont allow it.
e.g
textbox1.text = copythiscode
textbox2.text = thisistext
wont allow. Because textbox2 contains "this"
i.e textbox2 Does not contains any combination of 4 or more characters from textbox1.
Posted
Updated 18-May-11 20:13pm
v6
Comments
Olivier Levrey 18-May-11 7:26am    
I don't understand why you split your string if you don't want to separate the words...
Can you give an example of what you want to do?
bipin9 18-May-11 8:40am    
thank you
Kim Togo 18-May-11 9:00am    
Hi bipin9
If the solution has help you and you do not have any other questions. Then please press "Accept Answer"
Olivier Levrey 18-May-11 9:38am    
OP updated his question. Please see.
bipin9 18-May-11 9:29am    
private void button2_Click(object sender, EventArgs e)
{
if (textBox2.Text.Length < 4)
{
textBox3.Text = "Password should be atleatst 4 character long";
}
else
{
findoccurance(textBox1.Text, textBox2.Text);
}

}
private void findoccurance(string source, string target)
{
if (source.Contains(target))
{
Console.Write("string contains {0}", target);
}
}

Based on updates from OP.

Try this regex string: (\w{3,})(?=.+\1)
This will find repeating words that is at least 3 char long or more disregards spacing.

C#
private bool CheckForRepeating(string text)
{
  return System.Text.RegularExpressions.Regex.IsMatch(text, @"(\w{3,})(?=.+\1)", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
}

// Test of method
bool test1 = CheckForRepeating("copythiscode");
// test1 is false

bool test2 = CheckForRepeating("copythiscodethisistext");
// test2 is true


You can do something like

C#
// any combination of 4 or more characters
bool test3 = CheckForRepeating(textbox1.Text + textbox2.Text);


If there is any repeating words from textbox1 in textbox2, this should make test3 = true.

----

You what to play with this regex string: (\w)\1{3}
It finds any alphanumeric with exact 4 repeating char.

Check out this great tool Expresso[^].

You can make a method that do a check like this.
C#
private bool CheckForRepeating(string text)
{
  return System.Text.RegularExpressions.Regex.IsMatch(text, @"(\w)\1{3}");
}

// Test of method
bool test1 = CheckForRepeating("password");
// test1 is false

bool test2 = CheckForRepeating("paaaassword");
// test2 is true
 
Share this answer
 
v4
Comments
lukeer 18-May-11 10:16am    
I believe OP doesn't want to exclude four identical characters but four in a row that match textbox1's Text property.
Am I right with this
1. Textbox1 is for user name.
2. Textbox2 is for password.
3. Password must be at least 4 characters long.
4. Password must not contain user name.

You did the length constrain (3.) yourself.
For (4.) this would do:
System.Text.RegularExpressions.MatchCollection matchCollection = System.Text.RegularExpressions.Regex.Matches(textbox2.Text, textbox1.Text);
if(matchCollection.Count > 0)
  Console.WriteLine("Password contains user name.");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900