RossJ
RossJ

Reputation: 615

Can cookie names start with a numerical digit?

Just a quick question, can a cookie name begin with a number (or only contain numerical digits)?

I can't find anything in the official specs that specifically says it's not allowed, but just wondering if it would cause any problems, both in browsers and when dealing with them in C# code (using MVC5):

Upvotes: 1

Views: 305

Answers (1)

kelvinmac
kelvinmac

Reputation: 301

According to mozilla reference https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#Directives

A <cookie-name> can be any US-ASCII characters except control characters (CTLs), spaces, or tabs. It also must not contain a separator character like the following: ( ) < > @ , ; : \ " / [ ] ? = { }

Therefore yes, you are allowed to have the cookies you described according to that reference - which makes sense given that the name is taken as a String-.

Since the Set Cookie is a function available in all browsers, it's safe to assume it will apply to most if not all major browsers.

Upvotes: 2

Related Questions