Solved

regular expression - 4 OR 6 digits

Posted on 2014-11-02
6
193 Views
Last Modified: 2014-11-02
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
0
Comment
Question by:websss
[X]
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
  • 3
  • 2
6 Comments
 
LVL 24

Accepted Solution

by:
mankowitz earned 500 total points
ID: 40418061
this should work: ^\d{4}$|^\d{6}$
0
 

Author Comment

by:websss
ID: 40418065
works for 4 digits but fails for 6
0
 
LVL 15

Expert Comment

by:Insoftservice
ID: 40418066
^[0-9]{4,6}$  
OR
/^\d{4|6}$/

would do the work
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:websss
ID: 40418067
^[0-9]{4,6}$  allows 5 digits

it needst to be 4 OR 6
0
 

Author Closing Comment

by:websss
ID: 40418069
i had a trailing space.... it worked!
0
 
LVL 15

Expert Comment

by:Insoftservice
ID: 40418071
I hope there would have been slight change in comment

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

749 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