简体   繁体   中英

Regular expression to Allow starting letters and then numbers or letters

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

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

But it is not working. Can anyone please help me out?

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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