Validate string position before using the index.