C# Regex: Checking for “a-z” and “A-Z”

前端 未结 3 1706
南笙
南笙 2020-11-29 10:33

I want to check if a string inputted in a character between a-z or A-Z. Somehow my regular expression doesn\'t seem to pick it up. It always returns true. I am not sure why,

3条回答
  •  爱一瞬间的悲伤
    2020-11-29 10:59

    Regex reg = new Regex("^[a-zA-Z]+$");
    
    • ^ start of the string
    • [] character set
    • \+ one time or the more
    • $ end of the string

    ^ and $ needed because you want validate all string, not part of the string

提交回复
热议问题