且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

javascript regex:仅允许英文字母

更新时间:2023-02-20 08:42:23

let res = /^[a-zA-Z]+$/.test('sfjd');
console.log(res);

注意:如果您有任何标点符号或其他任何东西,那么它们也都是无效的.短划线和下划线无效. \w涵盖a-zA-Z和其他一些单词字符.这完全取决于您的具体需求.

Note: If you have any punctuation marks or anything, those are all invalid too. Dashes and underscores are invalid. \w covers a-zA-Z and some other word characters. It all depends on what you need specifically.