Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Calculate number of nights between two dates 5 52
using sqldatareader to populate cells in Excel-syntax 6 15
Where is this file? 3 25
linq, c# 8 22
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

765 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