I have a number of DOM elements being dynamically created on a web page. Their IDs are generated from an external list and sometimes these names may contain illegal characters for an ID like "@" or "&".
I need to remove chracters that do not match the following rules:
- The string must begin with a letter
- The first character may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".")
So, if the original string is:
99% of People are not the 1%
Then the resulting string with illegal characters removed would be:
ofPeoplearenotthe1
Can anyone help me to write the regex in Javascript that will remove characters from a string that do not follow the above requirements?