dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #20763
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9644: Added method for checking if uid is valid
------------------------------------------------------------
revno: 9644
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-01-28 19:14:42 +0200
message:
Added method for checking if uid is valid
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/CodeGenerator.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/CodeGenerator.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/CodeGenerator.java 2013-01-16 10:46:53 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/CodeGenerator.java 2013-01-28 17:14:42 +0000
@@ -28,6 +28,7 @@
*/
import java.security.SecureRandom;
+import java.util.regex.Pattern;
/**
* @author bobj
@@ -42,6 +43,8 @@
public static final int NUMBER_OF_CODEPOINTS = allowedChars.length();
public static final int CODESIZE = 11;
+ private static final Pattern CODE_PATTERN = Pattern.compile( "^[a-zA-Z0-9]{11}$" );
+
/**
* Generates a pseudo random string using the allowed characters. Code is
* 11 characters long.
@@ -77,4 +80,15 @@
return new String( randomChars );
}
+
+ /**
+ * Tests whether the given code is valid.
+ *
+ * @param code the code to validate.
+ * @return true if the code is valid.
+ */
+ public boolean isValidCode( String code )
+ {
+ return code != null && CODE_PATTERN.matcher( code ).matches();
+ }
}