Reputation: 201
I want validate ID using java regex.
Here's the code I've tried:
boolean x=l.matches("(?i)[A-Z]{2}-\\[2-3]");
I used "HT-43" as input. I want to get answer as "YES" but I get "NO".
Upvotes: 2
Views: 1206
Reputation: 4191
You were close, try the following:
String num = "HT-43";
boolean x=num.matches("[A-Z]{2}-\\d{2,5}");
System.out.println(x);
Outputs:
true
Demo: https://regex101.com/r/UWGyB3/1
Upvotes: 3