Reputation: 58301
So I would like to know what's inside the string for example:
var str = "a"; // Letter
var str = "1"; // Number
var str = "["; // Special
var str = "@"; // Special
var str = "+"; // Special
Is there any pre defined javascript function for this? Otherwise I will make it with regex :)
Upvotes: 1
Views: 1435
Reputation: 11922
if (/^[a-zA-Z]$/.test(str)){
// letter
} else if (/^[0-9]$/.test(str)){
// number
} else {
// other
};
Of course this only matches one character so 'AA' would end up in the //other
section.
Upvotes: 3
Reputation: 498972
They are all strings...
There isn't anything built in that will do what you want.
A regex may be a good solution, though you have not really provided enough information for one.
Upvotes: 2