How to check if a String is in valid format or not in Java8

I want to validate if a given String is in below format or not.

String validString = "Emp_idIn645745,48576845,8347683,8734682";

some of the invalid Strings are below:

  • "EmpIdIn46374,49587,498576"
  • "Emp_Id=736437"

Will it be possible to achieve this in java 8?

>Solution :

If so, then it’s not a problem with Java 8. But it depends on what exact rules this string should contain. You will definitely have to build your own validator function.

I would start by checking the first part with <your-string>.startsWith("Emp_idIn").
For the numbers, you have to find your own way to validate them using your rules.

Leave a Reply