Wrox Programmer Forums
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 10th, 2011, 07:33 AM
Authorized User
 
Join Date: Aug 2006
Posts: 41
Thanks: 1
Thanked 0 Times in 0 Posts
Default RegEx.IsMatch always returns true

Hi all,
I've got a regular expression which checks for the existence of a uppercase, lowercase and number within a string. I've tested it with two regular expression tools and it works perfectly.

However when I call RegEx.IsMatch, it always returns true. Here's my code:

Code:
 
private static string _upperLowerNumericPattern = @"^(?!.*(.)\1{100,})((?=.*[\d]+)(?=.*[A-Z]+)(?=.*[a-z]+)).{0,}$";
 
public static string GenerateAlphaNumericValue(int length, bool mustContainUpperLowerCaseAndNumber)
{
if (length < 3 && mustContainUpperLowerCaseAndNumber)
throw new ArgumentException("Minimum length of string must be 3 characters if string must contain uppercase, lowercase and number.");
string generatedValue = string.Empty;
bool patternMatched = false;
while(!patternMatched)
{
//Call method to generate string - test by setting generatedValue to your own test value
generatedValue = GenerateAlphaNumericValue(length);
if(Regex.IsMatch(generatedValue,_upperLowerNumericPattern));
patternMatched = true;
}
return generatedValue;
}

Last edited by elwappo; November 10th, 2011 at 07:58 AM..
 
Old November 10th, 2011, 08:02 AM
Authorized User
 
Join Date: Aug 2006
Posts: 41
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Problem solved - semicolon at the end of the "if" statement. D'oh.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Regex pattern to match carriage returns inside quotation marks? miikee55 Classic ASP Basics 4 September 21st, 2009 06:04 AM
Regex.IsMatch - receive a parsing error smcirish VB How-To 1 June 14th, 2007 12:21 AM
SmartNavigation="true" CraigJones ASP.NET 1.0 and 1.1 Basics 2 September 3rd, 2004 01:29 PM
True DBGrid 8.0 KalluMama Pro VB 6 1 August 10th, 2004 01:39 AM
Stupid but true Adam H-W SQL Server 2000 3 December 6th, 2003 12:16 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.