Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / June 2007

Tip: Looking for answers? Try searching our database.

Simple Regex

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
shapper - 12 Jun 2007 15:52 GMT
Hello,

I need a regex expression that allows only numbers in the following
format:

2312-986

The first number can't start with 0:
0231-123 is invalid.

However:
1231-012 is valid

Could someone help me out?

Thanks,
Miguel
Peter Bradley - 12 Jun 2007 16:15 GMT
[1-9]\d{3}-\d{3}

Ought to do it, I would think.  It checks out in my RegEx checker, anyway,
using the examples you give.

Peter

> Hello,
>
[quoted text clipped - 13 lines]
> Thanks,
> Miguel
Peter Bradley - 12 Jun 2007 16:44 GMT
Sorry to reply to myself, but I miscopied my RegEx.  It should, of course,
be:

^[1-9]\d{3}-\d{3}$

Since I'm assuming you want simply this format and nothing else.  If you
leave the start and finish markers (^, $) out then it will match the format
anywhere in the expression.
e.g. 2222abd1234-023xxxx would match

Apologies

Peter

> [1-9]\d{3}-\d{3}
>
[quoted text clipped - 20 lines]
>> Thanks,
>> Miguel
Mark Rae - 12 Jun 2007 16:18 GMT
> Could someone help me out?

[1-9][0-9][0-9][0-9]-[0-9][0-9][0-9]

I'm sure there are much shorter and cleverer ways using groups etc...

Signature

http://www.markrae.net


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.