I am new to regex. I need a regex pattern to validate the input text field that can accept string without special character. If "@" is added it should validate for email field. I have tried with following.
[a-zA-Z0-9\s._-]{3,}(?(?=@)[a-z0-9.-]+\.[a-z]{2,3}|$
You can use your regex with small changes:
[a-zA-Z0-9\s._-]{3,}(?:@[a-z0-9.-]+\.[a-z]{2,3}|$)
Basically it now matches either the part with @ or end of string.