Maxime Savard
Maxime Savard

Reputation: 128

Java Match string format

So I want to match a string to a simple mask but I would like to avoid using regex because my client have access to this mask and can change it.

Is it possible to have a string matches something like #####-000?

Or I have no choice but to convert my simple mask to regex ?

Thank you.

Upvotes: 1

Views: 108

Answers (1)

Chris311
Chris311

Reputation: 3992

If I get your question (and the comments) the right way, you could do the following:

  • Split your string at '-'
  • Check if string before '-' has length 5 and is numeric (StringUtils.isNumeric(...))
  • Check if the string after '-' equals '000'

Upvotes: 1

Related Questions