tags:

views:

35

answers:

2

I'm trying to find a regex that will check for a valid mask. The mask can contain as many * as it would like but it has to be followed by only 4 numbers. For example I would like these to pass:

********1234
******1234

and these to fail:

********123
********12345
******12*34
******1234*

Thanks for your help.

+2  A: 
/^\*+\d{4}$/

This pattern will look for an entire string that starts with one or more asterisk (\*+), followed by exactly four digits (\d{4}, which could also be expressed as [0-9]{4}).

Daniel Vandersluis
+2  A: 

Try this

^\*+\d{4}$

or, if you're stuck in a language without \d

^\*+[0-9]{4}$
Cassy
Perfect, thanks!