rossko57
(Rossko57)
August 4, 2022, 12:05pm
14
Comment, for info only - invalid Item names beginning with digits have been seen to cause “mysterious” problems with DSL rule triggers, old-style sitemaps, and persistence services.
All of those are difficult issues to solve until someone reveals/spots the invalid name, so I for one welcome the new stricter validation
Background
opened 10:42AM - 05 Feb 21 UTC
closed 10:35AM - 23 May 22 UTC
In the docs under [Items -> Name](https://www.openhab.org/docs/configuration/ite… ms.html#name) there is the following sentence:
> "The Item name is used to uniquely identify an Item. The name must be unique across all .items files in your openHAB configuration. The only characters permitted in an Item name are letters, numbers and the underscore character. Names must not begin with numbers. Spaces and special characters are not permitted."
**It is therefore forbidden to begin the name of an item with a number?**
In the code (openHAB-core) there is the function "isValidItemName" in "ItemUtil", which checks for the following conditions:
1. itemName != null
2. !itemName.isEmpty()
3. itemName.matches("[a-zA-Z0-9_]*")
This is the code [ItemUtil.java#L56](https://github.com/openhab/openhab-core/blob/main/bundles/org.openhab.core/src/main/java/org/openhab/core/items/ItemUtil.java#L56):
```java
/**
* Returns {@code true} if the specified name is a valid item name, otherwise {@code false}.
* <p>
* A valid item name must <i>only</i> only consists of the following characters:
* <ul>
* <li>a-z</li>
* <li>A-Z</li>
* <li>0..9</li>
* <li>_ (underscore)</li>
* </ul>
*
* @param itemName the name of the item to be checked (could be null or empty)
* @return true if the specified name is a valid item name, otherwise false
*/
public static boolean isValidItemName(final @Nullable String itemName) {
return itemName != null && !itemName.isEmpty() && itemName.matches("[a-zA-Z0-9_]*");
}
```
However, the regex only checks:
> A valid item name must only consist of the following characters:
> * a-z
> * A-Z
> * 0..9
> * _ (underscore)
**However, no attention is paid to whether the item name starts with a number or not.**
In some of my projects I also use item names that start with a number and never had any problems with that.
Now I wanted to ask which of these is correct?
- Are the item names that start with a number allowed and we have to adapt the documentation?
- Are the item names that start with a number not allowed and we have to adapt the code?