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

| Views: 1810
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', '', 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.
static final Pattern UID_PATTERN = Pattern.compile("[[0-9]+\\.]*");

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


Have comments or feedback on what I wrote? Please share them below! Found this useful? Consider sending me a small tip.
comments powered by Disqus
Other posts you may like...