Regular expression to Allow starting letters and then numbers or letters

前端 未结 2 1861
北恋
北恋 2020-12-20 20:22

I need regular Expression which should start with letters only and later it can contain numbers or letters.But starting should contain letters only. I have used



        
相关标签:
2条回答
  • 2020-12-20 20:45

    The regex you are using is pretty good. The problem with this: ^[a-zA-Z]*[a-zA-Z0-9]+$ is that you are using the * operator, which denotes 0 or more repetitions. If you want it to start with a letter, just use this: ^[a-zA-Z][a-zA-Z0-9]*$. This will match a letter an any letters or numbers which might follow.

    0 讨论(0)
  • 2020-12-20 20:51

    You used the wrong cardinality. Use + (at least one) instead of * (0 or more), as shown below:

    ^[a-zA-Z]+[a-zA-Z0-9]*$
    
    0 讨论(0)
提交回复
热议问题