简体   繁体   English

如何为仅以字母开头的用户名制作正则表达式?

[英]How can I make regular expression for username that only starts with alphabet?

I'm trying to create a regular expression that will allow only specific usernames我正在尝试创建一个只允许特定用户名的正则表达式

  • Only starts with alphabet.仅以字母开头。
  • Only ends with either number or an alphabet.仅以数字或字母结尾。
  • Only allowed - if contains alphabets only or only one dot with alphabets, only one underscore with alphabets.仅允许 - 如果仅包含字母或仅包含一个带字母的点,则仅包含一个带字母的下划线。
  • Cannot starts with dot or underscore不能以点或下划线开头
  • Length of username should be only in 4 to 10 char用户名的长度应该只有 4 到 10 个字符

this is what i am doing - ^(?=[a-zA-Z0-9._]{4,10}$)(?..*[_.]{2})[^_.].*[^_.]$这就是我正在做的 - ^(?=[a-zA-Z0-9._]{4,10}$)(?..*[_.]{2})[^_.].*[^_.]$

This should work for you:这应该适合你:

^(?=[a-zA-Z0-9._]{4,10})[a-zA-Z](?:[a-zA-Z]+_[a-zA-Z0-9]+|[a-zA-Z]+\.[a-zA-Z0-9]+|[a-zA-Z0-9]+)$

If the only problem currently is that it should not start with numbers, you could use one of these patterns that start the match with a char [A-Za-z] and ends the match with [a-zA-Z0-9]如果当前唯一的问题是它不应该以数字开头,您可以使用以下模式之一,以 char [A-Za-z]开始匹配并以[a-zA-Z0-9]结束匹配

In the middle there can only be 1 occurrence of either .在中间只能出现 1 次. or __

^(?=[a-zA-Z0-9._]{4,10}$)(?!.*[_.]{2})[A-Za-z]+(?:[_.][a-zA-Z0-9]+)?$

Regex demo正则表达式演示

Or another variation:或另一种变体:

^[a-zA-Z](?=[a-zA-Z0-9._]{3,9}$)[a-zA-Z0-9]*(?:[._][a-zA-Z0-9]*)?[a-zA-Z0-9]$

Regex demo正则表达式演示

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

相关问题 如何使 python 中的正则表达式仅匹配字母数字而不匹配数字或字母字符? - How can I make regular expression in python match only alphanumeric and not numerical or alphabet characters? 如何使此正则表达式起作用? - How can I make this regular expression work? 仅字母和数字但不包含空格的正则表达式 - Regular expression for only alphabet and number but not space 如何制作仅匹配嵌套括号中间括号的正则表达式? - How can I make a regular expression that only matches the middle bracket of nested brackets? 如何验证使用正则表达式开头和不开头? - How to validate Starts with and Not Starts using Regular Expression? 如何编写以特定单词匹配开头的正则表达式,并持续到达到句点 - How can I write a regular expression that starts with a particular word match and continues until it hits a period ACR 清除 - 如何设置正则表达式以跳过清除以 v 开头的特定图像 - ACR purge - How can i set regular expression to skip specific image which starts with v from purging 如何使Perl正则表达式的一部分可选? - How can I make part of a Perl regular expression optional? 如何使正则表达式不会导致“灾难性的回溯”? - How can I make the regular expression not result in “catastrophic backtracking”? 如何使正则表达式匹配大小写? - How can I make a regular expression match upper and lower case?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM