Function Repository Resource:

ValidCASNumberQ

Source Notebook

Check for a valid Chemical Abstracts Service (CAS) Registry Number

Contributed by: Jan Mangaldan

ResourceFunction["ValidCASNumberQ"][s]

checks if s is a valid Chemical Abstracts Service (CAS) Registry Number.

Details

A CAS Registry Number is assigned to a substance when it enters the Chemical Abstracts Service (CAS) Registry database.
CAS Registry Numbers are universally recognized and used to provide a unique, unmistakable identifier for chemical substances and are assigned in sequential order to unique, new substances identified by CAS scientists for inclusion in the CAS Registry.
CAS Registry Numbers are numeric identifiers that can contain from 4 up to 10 digits, divided by hyphens into three parts. The third part is a check digit.
ResourceFunction["ValidCASNumberQ"] can accept CAS Registry Numbers as String or Integer arguments or as ExternalIdentifier objects.

Examples

Basic Examples (2) 

The CAS number for aspirin:

In[1]:=
ChemicalData["Aspirin", "CASNumber"]
Out[1]=

Check that this result is a valid CAS number:

In[2]:=
ResourceFunction["ValidCASNumberQ"][%]
Out[2]=

Scope (4) 

When supplied to ValidCASNumberQ as a String, the CAS number may or may not have hyphens:

In[3]:=
ResourceFunction["ValidCASNumberQ"]["171599-83-0"]
Out[3]=
In[4]:=
ResourceFunction["ValidCASNumberQ"]["171599830"]
Out[4]=

ValidCASNumberQ also accepts Integer arguments:

In[5]:=
ResourceFunction["ValidCASNumberQ"][171599830]
Out[5]=

ValidCASNumberQ can be used on ExternalIdentifier objects:

In[6]:=
ResourceFunction["ValidCASNumberQ"][
 ExternalIdentifier["CASRegistryNumber", "171599-83-0"]]
Out[6]=

ValidCASNumberQ returns False for everything else:

In[7]:=
ResourceFunction["ValidCASNumberQ"]["xxx"]
Out[7]=
In[8]:=
ResourceFunction["ValidCASNumberQ"][Pi]
Out[8]=

Version History

  • 1.1.0 – 12 July 2021
  • 1.0.0 – 23 December 2020

Related Resources

License Information