By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,215 Members | 1,920 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,215 IT Pros & Developers. It's quick & easy.

Use of [ and ] within id or name attribute of <input /> tag

P: n/a


I am wanting to know whether [ and ] are XHTML1-valid characters for use
within an id attribute and/or a name attribute.

http://validator.w3.org/check?uri=ht...ss=1&verbose=1

(e.g. see line 77) suggests that it is valid, but the spec suggests that
it is not.
More detail:

I have a form containing a variety of input elements, including a checkbox
array.

For ease of processing the form, it would be helpful if the name of each
element in the checkbox array could include [ ] e.g.

<input type="checkbox" name="formname[checkbox][number]" />

However, looking at the HTML4 spec, which XHTML1.0Transitional piggy-backs
onto, the specification suggests that [ and ] are not valid characters for
use within this:

http://www.w3.org/TR/html401/types.html#type-name

"ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
followed by any number of letters, digits ([0-9]), hyphens ("-"),
underscores ("_"), colons (":"), and periods (".")."

However, a page I have online at present which uses [ ] does validate to
XHTML1.0Transitional:

http://validator.w3.org/check?uri=ht...ss=1&verbose=1

eg. line 77 contains name="main[function]"

Is [ and ] therefore valid?


Martin Lucas-Smith www.geog.cam.ac.uk/~mvl22
www.lucas-smith.co.uk

Jul 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a


Martin Lucas-Smith wrote:

I am wanting to know whether [ and ] are XHTML1-valid characters for use
within an id attribute and/or a name attribute.

http://validator.w3.org/check?uri=ht...ss=1&verbose=1

(e.g. see line 77) suggests that it is valid, but the spec suggests that
it is not.
More detail:

I have a form containing a variety of input elements, including a checkbox
array.

For ease of processing the form, it would be helpful if the name of each
element in the checkbox array could include [ ] e.g.

<input type="checkbox" name="formname[checkbox][number]" />

However, looking at the HTML4 spec, which XHTML1.0Transitional piggy-backs
onto, the specification suggests that [ and ] are not valid characters for
use within this:

http://www.w3.org/TR/html401/types.html#type-name

"ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
followed by any number of letters, digits ([0-9]), hyphens ("-"),
underscores ("_"), colons (":"), and periods (".")."

However, a page I have online at present which uses [ ] does validate to
XHTML1.0Transitional:

http://validator.w3.org/check?uri=ht...ss=1&verbose=1

eg. line 77 contains name="main[function]"

Is [ and ] therefore valid?


When you look at
http://www.w3.org/TR/xhtml1/dtds.htm...onal.dtd_input
you will see that the name attribute of <input> is of type CDATA
therefore for XHTML 1.0 transitional the [] in a name attribute value of
an <input> element will pass validation with an XML parser.
The id attribute is defined to be of type ID and that doesn't allow [ or ].
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2

P: n/a


[Summary: Can anyone point me to a definitive reference of where the
allowed characters for a valid XHTML name attribute (of an input/form) tag
is, so I can make a regexp from this (or even also provide me with a
regexp!)?]
A while ago I posted to this list wanting to know whether [ and ] are
XHTML1-valid characters for use within an id attribute and/or a name
attribute. I need to apply this more generally now beyond just [].

Ultimately, I'm trying to get an regexp for validating a form API-supplied
name for both an input tag (<input name="something" ... /> and for a form
name <form name="something">, i.e. in PHP

$formName = 'name';

$regexp = '[something]';
if (!ereg ($regexp, $formName)) {
'The form name must consist of characters....
}


I understand that in HTML4, [] and are allowed this is not the case:
http://www.w3.org/TR/html401/types.html#type-name

"ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
followed by any number of letters, digits ([0-9]), hyphens ("-"),
underscores ("_"), colons (":"), and periods (".")."


But that in XHTML the allowed characters are different (as I have been
told they include []) :

When you look at
http://www.w3.org/TR/xhtml1/dtds.htm...onal.dtd_input
you will see that the name attribute of <input> is of type CDATA
therefore for XHTML 1.0 transitional the [] in a name attribute value of
an <input> element will pass validation with an XML parser. The id
attribute is defined to be of type ID and that doesn't allow [ or ]. --


However, I can't see where exactly the CDATA type is defined for XHTML
Transitional, which is the doctype I'm using? Therefore:
** Can anyone point me to a definitive reference of where the allowed
characters for a valid XHTML name attribute (of an input/form) tag is, so
I can make a regexp from this (or even also provide me with a regexp!)? **

Martin

Jul 20 '05 #3

P: n/a
Martin Lucas-Smith wrote:
[Summary: Can anyone point me to a definitive reference of where the
allowed characters for a valid XHTML name attribute (of an input/form) tag
is, so I can make a regexp from this (or even also provide me with a
regexp!)?] [snip] I understand that in HTML4, [] and are allowed this is not the case:
> http://www.w3.org/TR/html401/types.html#type-name
>
> "ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
> followed by any number of letters, digits ([0-9]), hyphens ("-"),
> underscores ("_"), colons (":"), and periods (".")."
[snip]

You are confusing data types with attributes. The name attribute for the
<input> element type is clearly listed as being CDATA, not ID or NAME
tokens:

<URL:http://www.w3.org/TR/html401/interact/forms.html#h-17.3>
<URL:http://www.w3.org/TR/html401/interact/forms.html#h-17.4>

The only real restriction on what characters can appear in form control
names is when a form is submitted with GET:

"The "get" method restricts form data set values to ASCII characters."

-- <URL:http://www.w3.org/TR/html401/interact/forms.html#h-17.13.1>

However, I can't see where exactly the CDATA type is defined for XHTML
Transitional, which is the doctype I'm using?

[snip]

<URL:http://www.w3.org/TR/REC-xml#attdecls>

--
Jim Dabell

Jul 20 '05 #4

P: n/a

[Summary: Can anyone point me to a definitive reference of where the
allowed characters for a valid XHTML name attribute (of an input/form)
tag is, so I can make a regexp from this (or even also provide me with
a regexp!)?]
You are confusing data types with attributes. The name attribute for
the <input> element type is clearly listed as being CDATA, not ID or
NAME tokens:


I must confess I don't fully understand how the spec is read :), hence my
question.

The only real restriction on what characters can appear in form control
names is when a form is submitted with GET:

"The "get" method restricts form data set values to ASCII characters."

-- <URL:http://www.w3.org/TR/html401/interact/forms.html#h-17.13.1>

Erm, I'm strictly referring to what appears as XXX in the following:

<input name="xxx" ... />

Can anyone supply an unambiguous reference/regexp as to what xxx can be
for the page still to validate as XHTML?

Martin

Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.