Home > front end >  Check that string matches mask format without regex
Check that string matches mask format without regex

Time:12-26

I have mask from backend, for example this mask can be like this: "99-99-99" where 9 - any integer value

How I can check that entered by user string matches with this mask?

Backend doesn't send regex so I can't use it

CodePudding user response:

You can convert your pattern to a regex and use it. Because your pattern is not a standard pattern, you should convert it based on your needs. For example, you can check your mentioned pattern with a code like this :

"your pattern".replace("9", "\\d").toRegex().matches("your input")
  • Related