开发者

Most efficient way to check that string variable is a single alphanumeric character

I could do it with regex (something like myString.match(/^[A-Za-z0-9]开发者_StackOverflow$/)) but it seems like an overkill.

What would be more effective performance-wise?

Thanks.


Use the length property and the charCodeAt( 0 ) function to check the range of the ASCII value...


Well obviously, the most efficient is an indexed lookup into an array (pre-configured with appropriate boolean results). This is a very bad approach, in general, however. (Because it's non-standard and almost certainly not neccessary).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜