There is also the method validateSystemNameFormat
that can be used:
name = [...get from external program...]
try:
sensors.validateSystemNameFormat(name)
except jmri.NamedBean.BadSystemNameException:
print 'invalid name'
Which will check if the name is potentially valid (i.e. could be used), but will not create a Sensor. Note that this method does not check if the sensor name in question is really associated with a sensor, but merely checks if the name could be used.