Validate if String UUID is valid in Java

This page summarizes the projects mentioned and recommended in the original post on dev.to

InfluxDB - Power Real-Time Data Analytics at Scale
Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
www.influxdata.com
featured
SaaSHub - Software Alternatives and Reviews
SaaSHub helps you find the best software and product alternatives
www.saashub.com
featured
  • hibernate-validator

    Hibernate Validator - Jakarta Bean Validation Reference Implementation

  • /* * This code is based on this PR: https://github.com/hibernate/hibernate-validator/pull/1199 * All credits to Daniel Heid (dheid). I just made some adjustments. * In order to apply this on your situation, just create this class and call the method "isValidStringUUID". As its param, pass in your string UUID. */ public class UUIDValidator { enum LetterCase { /** * Only lower case is valid */ LOWER_CASE, /** * Only upper case is valid */ UPPER_CASE, /** * Every letter case is valid */ INSENSITIVE } private static LetterCase letterCase = LetterCase.LOWER_CASE; private static final int[] GROUP_LENGTHS = { 8, 4, 4, 4, 12 }; public static boolean isValidStringUUID(String value) { if ( value == null ) { return false; } int valueLength = value.length(); if ( valueLength == 0 ) { return false; } else if ( valueLength != 36 ) { return false; } int groupIndex = 0; int groupLength = 0; int checksum = 0; for ( int charIndex = 0; charIndex < valueLength; charIndex++ ) { char ch = value.charAt( charIndex ); if ( ch == '-' ) { groupIndex++; groupLength = 0; } else { groupLength++; if ( groupLength > GROUP_LENGTHS[groupIndex] ) { return false; } int numericValue = Character.digit( ch, 16 ); if ( numericValue == -1 ) { // not a hex digit return false; } if ( numericValue > 9 && !hasCorrectLetterCase( ch ) ) { return false; } checksum += numericValue; } } // NIL UUID if ( checksum == 0 ) { return false; } return true; } private static boolean hasCorrectLetterCase(char ch) { if ( letterCase == null ) { return true; } if ( letterCase == LetterCase.LOWER_CASE && !Character.isLowerCase( ch ) ) { return false; } return letterCase != LetterCase.UPPER_CASE || Character.isUpperCase( ch ); } }

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts

  • Is throwing nullexceptions considered good style??

    1 project | /r/java | 1 Oct 2022
  • Gitea 1.17.0 released with support for maven packaging

    1 project | /r/java | 1 Aug 2022
  • Spring Boot — Power of Value Objects

    3 projects | dev.to | 4 Dec 2022
  • The Spring Data JPA findById Anti-Pattern

    1 project | /r/java | 16 Nov 2022
  • In One Minute : Hibernate

    1 project | dev.to | 14 Nov 2022