Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

I've been focusing on making sure that the input to my web services at work is correct. One of these inputs happens to be the root part of a HL7 OID, which is a dot-separated UID. The values look like this '1.2.3', '9.5.6.3.7774.1', etc. It's very similar to an IP address, but can have more than 4 parts.

This is a very simple pattern I'm using for validation. It assumes that the input is non-null and not an empty string.
 Java
static final Pattern UID_PATTERN = Pattern.compile("[[0-9]+\\.]*");


...then to use it, I do something like this...
 Java
if (!UID_PATTERN.matcher(myString).matches()) {
throw RuntimeException("String doesn't match the UID pattern");
}




-i

A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. Use of any information from my blog posts should be at own risk and I do not hold any liability towards any information misuse or damages caused by following any of my posts.

All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle). Use of any information contained in this blog post/article is subject to this disclaimer.
Hi! You can search my blog here ⤵
NOTE: (2022) This Blog is no longer maintained and I will not be answering any emails or comments.

I am now focusing on Atari Gamer.