Click here to Skip to main content
12,299,210 members (39,595 online)
Rate this:
 
Please Sign up or sign in to vote.
Hi,

I want to verify the characters entered in excel sheet' cell using vba. I'm trying this with the pattern "^[a-zA-Z0-9]{21,21}$". I want this to match exactly 21 characters (can be alphanumeric) and no more or less than that. Its working fine when the characters are less than 21 characters but not when they exceed. Please suggest me how could I achieve that.

I appreciate any help.

Thanks in Advance,
Sunny K
Posted 14-Jun-12 20:21pm
Comments
ryanb31 15-Jun-12 9:09am
   
You could also loop through each cell and use the LEN() function instead.
Sunnykumar08 16-Jun-12 5:14am
   
Hi ryanb, thanks for the suggestion. I'm already using this trick, but it's an overhead counting the characters every time if we're using a Regular expression to match. I want a definite solution. Thanks if you may assist me this way :)

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

I haven't tested it, but trying specifying 21 just once, like so:

^[a-zA-Z0-9]{21}$
  Permalink  
Comments
Sunnykumar08 16-Jun-12 3:35am
   
Hi Rick, I appreciate your help, but I already have given this a try but this didn't do the trick.
Kenneth Haugland 11-Jul-12 20:05pm
   
If you want alphanumeric values you should write somthing like this:
^[\w\,]{21}$

I only got matches if it had exactly 21 repititions. I fthis dosent work I would think that you have forgotten to add som of the charecters you search for.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160525.2 | Last Updated 15 Jun 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100