Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Regex, how to write multiple of 5 with limit to 25?

 
Ranch Hand
Posts: 74
MySQL Database Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am using Pattern annotation to validate a field that will only accept values 0-25.
My solution is this below, but written in this It is not how I want. Only one problem: digit which begin with 0 or 2, so when I write 5 is incorrect.


this is my field annotated:


I am using regexr.com/ to test the correct functioning of regex matching.
How can I fix?
Thanks !
 
Marshal
Posts: 76472
366
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That regex will not accept 5. Try ...[0-2]?...
The ? means 0 or 1 occurrence.
What do the colons mean?
 
manu lix
Ranch Hand
Posts: 74
MySQL Database Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:That regex will not accept 5. Try ...[0-2]?...
The ? means 0 or 1 occurrence.
What do the colons mean?



The colons It means that they are digits, but apparently in this case it is superfluous.
So, now comes close to what I want to achieve, the only problem with that is also valid 05.



Suggestions?
Thanks
 
Campbell Ritchie
Marshal
Posts: 76472
366
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try ...[1-2]?...
 
There is no beard big enough to make me comfortable enough with my masculinity to wear pink. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic