• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Regular Expressions and JavaScript

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to validate a 1 to 25 digit number. Example: 1 should work and 1234567890123456789012345 should work too and anything in between. No characters allowed. This is an expression that worked for a 1-3 digit number for me in the past:

var number = /\d$|(\d\d$)|(\d\d\d$)/;

However, for a 1-25 digit number that would be to long of an expression to do. I have tried:

\d{1,3}/; and \d{1,}

With these two it allowed numbers mixed in with letters, for example 12w3, it did however pick up all letters like aaaa. Any ideas?
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
/^\d{1,25}$/

What it means:
^ start of sting
\d number same as [0-9]
{x,y} range it must appear
$ endof string

Eric

[edit - fixed typo]
[ July 26, 2006: Message edited by: Eric Pascarello ]
 
ed suttner
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks eric, that did not work for me but you showed me what the $ does, this expression does work for me:

/^\d{1,25}$/

Can I use this same expression in java if I want to have server-side validation? Thanks again eric!
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
whoops, yep there was a typo ! fixed it....

Eric
 
Do you pee on your compost? Does this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic