简体   繁体   English

无法正确使用RegEx

[英]Can't get the RegEx right

The function checks out and everything works, I'm really just having trouble getting a pattern search that fits what I want. 该功能签出,一切正常,我真的很难获得适合我想要的模式搜索。 I'm trying to get a handle on RegEx's but they're a bit confusing to be honest. 我正在尝试了解RegEx,但是老实说,它们有些令人困惑。 I'm trying to make it so the user's input is only accepted if it's a capital letter followed by lowercase letters, to maximum of ten letters and minimum of three. 我正在尝试这样做,以便仅当用户输入是大写字母后跟小写字母时才接受用户输入,最多10个字母,最少3个字母。 Can anyone give me a RegEx that fits this? 谁能给我合适的RegEx吗?

$("#name").blur(function() {
    var pattern = /^[A-Z]+[a-z]$/;
    if (document.account.name.value.search(pattern) == -1) {
        $("#namemessage").text("Name must be a single capitalized word with no special characters");
        nameerror = 1;
    }
    else {
        $("#namemessage").text("");
        nameerror = 0;
    }
});

How about something like this? 这样的事情怎么样?

/^[A-Z][a-z]{2,9}$/

In English: capital letter, followed by 2 to 9 lowercase letters. 英文:大写字母,后跟2到9个小写字母。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM