Search code examples
javaregexdroolsnumber-formatting

Format Validation Numeric Java?


I have a task to validate xml messages through Drools implementation in Java.

In a particular drool implementation I am asked to validate a field through n..5 format.

I am using regex for format checking like:

SampleText.matches("[0-9]") 

For the n..5 It means the field max length is 5 'digits'? Or it means that the field has to be always 5 digits in length?

I assume that it has to do with the max length is it right?

Merry Christmas and sorry for the dumb question Thank you in advance


Solution

  • To specify the exact number of characters/digits you can use {}, i.e.:

    SampleText.matches("\d{5}") // matches 5 digits