Link to home
Start Free TrialLog in
Avatar of websss
websssFlag for Kenya

asked on

regular expression - 4 OR 6 digits

Hi

I need a regular expression to validate the user input
it has to be numeric
and it has to be either 4 or 6 digits

i'm not bothered about someone entering all zeros
ASKER CERTIFIED SOLUTION
Avatar of mankowitz
mankowitz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of websss

ASKER

works for 4 digits but fails for 6
^[0-9]{4,6}$  
OR
/^\d{4|6}$/

would do the work
Avatar of websss

ASKER

^[0-9]{4,6}$  allows 5 digits

it needst to be 4 OR 6
Avatar of websss

ASKER

i had a trailing space.... it worked!
I hope there would have been slight change in comment

^[0-9]{4,7}$
and it would have worked right ?