开发者

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

开发者 https://www.devze.com 2023-03-22 04:46 出处:网络
In JavaScript, how can I find out whether a string has a-z in it? Is there a simple funct开发者_如何学编程ion?With

In JavaScript, how can I find out whether a string has a-z in it? Is there a simple funct开发者_如何学编程ion?


With

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

I guess.


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_]


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?

0

精彩评论

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