Function Repository Resource:

ValidSymbolIdentifierQ

Source Notebook

Check whether a string is a valid symbol name

Contributed by: Brenton Bostick

ResourceFunction["ValidSymbolIdentifierQ"]["string"]

returns True if the string is a valid symbol identifier and returns False otherwise.

Details

ResourceFunction["ValidSymbolIdentifierQ"] does not generate any messages.
ResourceFunction["ValidSymbolIdentifierQ"] does not create new symbols.

Examples

Basic Examples (2) 

Check whether "x" is a valid symbol name:

In[1]:=
ResourceFunction["ValidSymbolIdentifierQ"]["x"]
Out[1]=

Check a string number:

In[2]:=
ResourceFunction["ValidSymbolIdentifierQ"]["6.7"]
Out[2]=

Properties and Relations (3) 

Symbols can not start with numbers:

In[3]:=
ResourceFunction["ValidSymbolIdentifierQ"]["2x"]
Out[3]=

Number characters can be later in the symbol:

In[4]:=
ResourceFunction["ValidSymbolIdentifierQ"]["a1b"]
Out[4]=

Characters besides letters and digits are not valid in symbols:

In[5]:=
ResourceFunction["ValidSymbolIdentifierQ"]["a1__b"]
Out[5]=

Spaces are invalid:

In[6]:=
ResourceFunction["ValidSymbolIdentifierQ"]["a b"]
Out[6]=

Publisher

Brenton Bostick

Version History

  • 1.0.0 – 26 March 2021

Related Resources

License Information