正则表达式模式不以数字开头,但必须是由字母数字字符和短横线组成。

huangapple go评论71阅读模式
英文:

regex pattern to not start with numbers but has to be alphanumeric with dash

问题

pattern="^(?!0-9+)[a-zA-Z0-9\d-]+$"
pattern="^[a-zA-Z][A-Za-z0-9_]*\S+$"

英文:

I'm looking for a html regex pattern to not accept numbers in the start of a string and no spaces but can allow alphanumeric with dash . Example " February-2023 " but not "2023February"

I tried the following patterns:

 pattern="^(?!0-9+)[a-zA-Z0-9\d\-]+$"
 pattern="^[a-zA-Z][A-Za-z0-9_]*\S+$"

答案1

得分: 0

^[a-zA-Z]([a-zA-Z0-9]*-[a-zA-Z0-9]*)+$

英文:

If you need hyphen/dash is mandatory, try this one: ^[a-zA-Z]([a-zA-Z0-9]*-[a-zA-Z0-9]*)+$

huangapple
  • 本文由 发表于 2023年2月27日 14:34:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/75577374.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定