Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular Expression help

Status
Not open for further replies.

bamboo

Programmer
Aug 22, 2001
89
US
I'm a newbie to RegExp. I'm having trouble validating a text field to only allow 8 characters, using any combination of 0-9, A-F. I have the following which validates fine for A-F, 8.

var targetChar = /[abcdef]{8}/

However I need to test for 0-9 as well. I know \d matches any digit [0-9] however I can't seem to get this to work when adding this in. Any help would be great. Thanks much.
 
Thanks CLFlaVA. That seems to work fine. However if I type in aa1122bbz it doesn't validate. However if I do the opposite zbb2211aa it does validate. It's seem that it validates only the first 8 characters. After that it doesn't seem to care. It should throw the alert since there are 9 characters correct?
 
Awesome! That was the trick. I was just reading up on negated character class. Thanks again. I appreciate it!
 
bamboo said:
I was just reading up on negated character class.
Just to muddy the waters further, in this case [tt]^[/tt] does not negate the character class: typing a caret after the opening square bracket will negate the character class.

In this case [tt]^[/tt] is an anchor representing the start of the string, and [tt]$[/tt] represents the end.

We love regex :)

---
Marcus
better questions get better answers - faq581-3339
accessible web design - zioncore.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top