同时包含不超过3个字母的正则表达式不应接受1a1a1a1a1 [英] regular expression with no more than 3 alphabets concurrently should not accept 1a1a1a1a1

查看:251
本文介绍了同时包含不超过3个字母的正则表达式不应接受1a1a1a1a1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不应该接受:1a1a1a1a1,aaaa11111,2222aaa33a 任何地方只能允许3个字符,不应该超过3个字符 我尝试如下,但失败了

should not accept: 1a1a1a1a1, aaaa11111 ,2222aaa33a only allow 3 characters anywhere no more than three should not allowed I tried like below but failed

var patt = new RegExp("([A-Za-z]){4}");
var result = patt.test(DLnumber);
if (result == true) {
    alert("No more than three alphabets are allowed");
    return false;
}

推荐答案

我认为这可能是您想要的:

I thin this may be what you look for:

if (str.replace(/[^a-z]/gi, "").length>3) {
    alert("No more than three alphabets are allowed");
    return false;
}

它计算字符串中按字母顺序排列的字符...

It counts the Alphabetical chars in the string...

这篇关于同时包含不超过3个字母的正则表达式不应接受1a1a1a1a1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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