Solved

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

Posted on 2008-10-24
1
534 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

777 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