javascript regex:仅允许英文字母 [英] javascript regex : only english letters allowed

查看:53
本文介绍了javascript regex:仅允许英文字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

快速问题:我需要允许输入仅接受从a到z以及从A到Z的字母,但是找不到用于此的任何表达式.我想使用javascript test()方法.

Quick question: I need to allow an input to only accept letters, from a to z and from A to Z, but can't find any expression for that. I want to use the javascript test() method.

推荐答案

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.

这篇关于javascript regex:仅允许英文字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆