What characters are allowed in the HTML Name attribute inside input tag?

DLH picture DLH · Aug 6, 2010 · Viewed 47.9k times · Source

I have a PHP script that will generate <input>s dynamically, so I was wondering if I needed to filter any characters in the name attribute.

I know that the name has to start with a letter, but I don't know any other rules. I figure square brackets must be allowed, since PHP uses these to create arrays from form data. How about parentheses? Spaces?

Answer

Matthias Samsel picture Matthias Samsel · Dec 13, 2012

Note, that not all characters are submitted for name attributes of form fields (even when using POST)!

White-space characters are trimmed and inner white-space characters as well the character . are replaced by _. (Tested in Chrome 23, Firefox 13 and Internet Explorer 9, all Win7.)