Search code examples
javascriptregexicd

Regex for determining if Alphanumeric code is in range


I'm working on an ICD10 diagnosis code application. I need to determine if one ICD10 code falls in a certain range. For example:

Code: 4A1H7EZ

Range: 4A1H7CZ - 4A1H7HZ

This should return 'True'.

I've tried converting the alpha characters to numbers (a=0, b=1 etc) but the resulting number conflicts with other ranges/codes.

Regex isn't my strong point, any suggestions would be appreciated.


Solution

  • Do you have to use regex? As seen here in comparing 2 strings alphabetically for sorting purposes javascript auto compares strings.

    So "4A1H7EZ" > "4A1H7CZ" && "4A1H7EZ" < "4A1H7HZ" will return true