Solved

Regular Expressions: need to check when 6 alpha/numeric characters have been entered

Posted on 2008-10-24
1
524 Views
Last Modified: 2008-10-24
I would like to use Regular Expressions to test if a string has 6 alpha/numeric characters, less than 6 or more than 6.

How do I do that?


Bob
0
Comment
Question by:newbieweb
1 Comment
 
LVL 2

Accepted Solution

by:
Clausewitz earned 500 total points
ID: 22798069
For the regular expression you can use this snippet.

public bool IsAlphaNumeric(String strToCheck)
{
Regex objAlphaNumericPattern=new Regex("[^a-zA-Z0-9]");
return !objAlphaNumericPattern.IsMatch(strToCheck);
}

You can check the stringlength with strToCheck.Length < 6

You cannot check both together in a single regular expression. So if you like e.g. alphanummeric strings with less than 6 chars you can check for:

if ( IsAlphaNumeric(myString) && myString.Length < 6) {}
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now