TIMEX
TIMEX

Reputation: 271634

How do I check if a string has an ASCII letter in it?

In JavaScript, how can I find out whether a string has a-z in it? Is there a simple function?

Upvotes: 0

Views: 840

Answers (3)

Puzo
Puzo

Reputation: 598

Try this one:

function checkkey(v) {
     if (/\W/.test(v.value)) {
        alert("Please enter alphanumerics only");
        return false;
     }
     return true;
}

W is a shortcut to [^a-zA-Z0-9_].

Change W to: [^a-zA-Z_]

Upvotes: 1

Joey
Joey

Reputation: 354396

With

/[a-z]/.test(myString)

I guess.

Upvotes: 5

Oded
Oded

Reputation: 498924

You can use a regular expression.

Not sure what you mean by a-z - that exact string, or simply lower case letters? Or do you mean something else?

Upvotes: 0

Related Questions