Exclude comma character from string without spaces

I need a regex expression that will check that the string does not have all spaces and that it does not contain a comma character (,).

I was able to find examples that do this or that, but not both:

^(?![\s,]*$).+ , to guarantee not all spaces and
^(.(?!,))*$ to exclude commas.

I have no way to use the code, this is a restriction on the field in the form.

+4
source share
1 answer

This should fit your needs:

 ^[^,]*[^ ,][^,]*$ 

"At least one char, which is not a space or comma surrounded by any char, but a comma"

+8
source

All Articles