Time is what we want the most, but what we use the worst. -- William Penn
steve souza
Ranch Hand
Joined: Jun 26, 2002
Posts: 852
posted
0
1) I suspect this would never be a bottleneck in a real application so it makes more sense to do which makes your vailidation the most flexible and easiest to maintain. Either way I would come up with a validate(...) method and hide the implementation.
2) If you really want to see performance differences run a lot of validations and time each approach.
3) You can also look at the source code. Here is a good site that has the java source. String.matches calls Pattern.matches. http://www.java2s.com/Open-Source/Java-Document/6.0-JDK-Core/Collections-Jar-Zip-Logging-regex/java/util/regex/Pattern.java.htm
Does your code work internationally? Its probably fine for ASCII, but the A in ASCII is American.
A major point of the generalized pattern stuff is to fit well into international code, I tend to think that languages such as Arabic or Tamil are not going to use American digits.