1

I understand the regex used to match if it contains all letters is ^[a-zA-Z]+$ so I thought a negation of this regex would be the answer and tried ^(?!^[a-zA-Z])+$ but it doesn't seem to work.

To provide some context, I'm creating a basic form using SurveyJS form creator that accepts custom validation only via regex. A certain form input should allow users to input anything and only throw an error if the user only fill in letters.

John Evans Solachuk
  • 1,953
  • 5
  • 31
  • 67

1 Answers1

1

You can use

^(?![a-zA-Z]+$).*

The negative lookahead ensures the whole line does not only contain a-zA-Z till the $ (end of line - thats why its included inside the lookahead - not outside of it) and the .* afterwards would match anything that passes the negative lookahead.

Demo: https://regex101.com/r/QuC2SQ/1

Patrick Artner
  • 50,409
  • 9
  • 43
  • 69