regex to check the string contains only letter and numbers but not only numbers

后端 未结 10 1448
温柔的废话
温柔的废话 2021-02-06 11:31

I need a help with regex which checks the string contains only letter and numbers but not only numbers

Valid

* letters
* 1wret
* 0123chars
* chars0123
*          


        
相关标签:
10条回答
  • 2021-02-06 12:10
    ^([a-zA-Z0-9]*)([a-zA-Z]+)([a-zA-Z0-9]*)$
    
    0 讨论(0)
  • 2021-02-06 12:12

    this should work ^([a-zA-Z0-9]*)([a-zA-Z]+)([a-zA-Z0-9]*)$ EDIT sry got the * and the + messed up

    0 讨论(0)
  • 2021-02-06 12:14

    Personally (I hate regex and find them generally to be hard to maintain), I'd do it in two steps.

    1. Is it all alphanumeric?
    2. Is there at least one letter?
    0 讨论(0)
  • 2021-02-06 12:14
    ([0-9]*[a-zA-Z]+)+
    
    0 讨论(0)
提交回复
热议问题