[英]Regular expression of string without number and char in javascript
I have no idea how to make the pattern of the regular expression of a line of string containing ONLY alphabet.我不知道如何制作仅包含字母表的字符串行的正则表达式模式。
var pattern = //the pattern is here;
var name = "My Name";
if(!pattern.test(name))
{
return true;
}
else {
return false;
}
Please, Help me.请帮我。
If you search a little bit about the basics of regex, you will find that you can use a pattern to match ranges, for instance:如果您搜索一下正则表达式的基础知识,您会发现可以使用模式来匹配范围,例如:
[A-Z] ----> will match letter from A to Z in upper case where
[a-z] ----> will match letter from A to Z in lower case.
[A-Za-z] -> will match all letters from A-Z case insensitive
Then, if you are lazy, you can use an insensitive flag like然后,如果你很懒惰,你可以使用一个不敏感的标志,比如
(?i)[a-z]
So, for your what you stated about ONLY alphabet, you can use:因此,对于您所说的 ONLY 字母表,您可以使用:
(?i)^[a-z]+$ But this won't match: `My Name` because you have a space.
(?i)^[a-z ]+$ This will match: `My Name`
You can read more on http://www.regular-expressions.info/quickstart.html您可以在http://www.regular-expressions.info/quickstart.html上阅读更多信息
Btw, if you show some effort in your question and post your attempt you can avoid community to downvote顺便说一句,如果您在问题中表现出一些努力并发布您的尝试,您可以避免社区投票
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.