CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions: Re: [ejaggers1] RE for number with or w/o comma: Edit Log



Zhris
Enthusiast

Jun 23, 2010, 9:09 PM


Views: 3150
Re: [ejaggers1] RE for number with or w/o comma

A basic expression which would allow commas to occur anywhere in the number string:

m/^[0-9,]+$/

Or an untested expression which would allow a comma after the first number or not, then after every 3 numbers or not, although it would allow i.e. "1,234,56789,444":

m/^\d\,?(\d{1,2}|\d{3}\,?)*$/

Sometimes I wonder if it would be easier to validate that the string contains just numbers or commas, remove all commas, then use sprintf to replace the commas in their proper places.

Chris


(This post was edited by Zhris on Jul 25, 2010, 6:31 AM)


Edit Log:
Post edited by Zhris (Enthusiast) on Jun 23, 2010, 9:12 PM
Post edited by Zhris (Enthusiast) on Jun 23, 2010, 9:13 PM
Post edited by Zhris (Enthusiast) on Jun 23, 2010, 9:13 PM
Post edited by Zhris (Enthusiast) on Jun 23, 2010, 9:18 PM
Post edited by Zhris (Enthusiast) on Jun 23, 2010, 9:21 PM
Post edited by Zhris (Enthusiast) on Jun 23, 2010, 9:23 PM
Post edited by Zhris (Enthusiast) on Jun 23, 2010, 9:25 PM
Post edited by Zhris (Enthusiast) on Jun 23, 2010, 11:49 PM
Post edited by Zhris (Enthusiast) on Jun 23, 2010, 11:50 PM
Post edited by Zhris (Enthusiast) on Jul 25, 2010, 6:30 AM
Post edited by Zhris (Enthusiast) on Jul 25, 2010, 6:30 AM
Post edited by Zhris (Enthusiast) on Jul 25, 2010, 6:31 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives