C# .NET - comparing two string using regular expression

Asked By Anjali agarwal on 07-Feb-13 05:15 PM

Hi All,

I have a password requirement change box for the users in asp.net. I am trying to write a regular expression where the four characters of the old passoword should not be same as the four characters of the new password string in C#. The code should return false if they are same.

Can I do this in regular expression, if not, is their any other quick way


Danasegarane Arunachalam replied to Anjali agarwal on 08-Feb-13 07:25 PM
How about this one

1. Compare the length of the strings and if they are equal then it is a valid password else not


protected bool validpassword(string newpassword, string oldpassword)
   if(newpassword.Trim().Length() == oldpassword.Trim().Length() )
     return true;
   return false;