Reputation: 1423
Need a regex for string such that:
Valid answers a) "hello world 123 -" b) "123 hello - world" c) "- hello 123 world"
Invalid answers a) "123456" b) "123456 " c) "abc>>>" c) "abc123>>>" d) ">>>>" The closest i've come up with is:
^([A-Za-z0-9 '\-!\£\$:;%&\*\(\)_=\+,.\?@\n\r\t]{1,20}$
But point 3 of "Can't have purely numbers" becomes invalid.
Any idea?
Upvotes: 1
Views: 104
Reputation: 785008
You can use this lookahead based regex:
^(?![0-9]+$)(?!.*?[<>{}\[\]#~^\/"]).{1,20}$
^ - Line start
(?![0-9]+$) - Not just numbers
(?!.*?[<>{}\[\]#~^\/"]) - Doesn't have these special characters
.{1,20} - 1 to 20 characters
$ - Line end
Upvotes: 1