有没有一种方法可以在Javascript中获取有效区域设置列表或检查区域设置是否有效?

4

我需要验证一些用户输入。据我所知,“en-US”是有效的HTTP区域设置,而“en_GB”则不是。有没有一种方法可以验证这个呢?

1个回答

1

这里是规格

The syntax and registry of HTTP language tags is the same as that defined by RFC 1766 1. In summary, a language tag is composed of 1 or more parts: A primary language tag and a possibly empty series of subtags:

    language-tag  = primary-tag *( "-" subtag )
    primary-tag   = 1*8ALPHA
    subtag        = 1*8ALPHA

[...] where any two-letter primary-tag is an ISO-639 language abbreviation and any two-letter initial subtag is an ISO-3166 country code. (The last three tags above are not registered tags; all but the last are examples of tags which could be registered in future.)

这里是国家代码列表。当然,“GB”在列表中。

en-GB是完全可以的,但en_GB不行。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接