I want to restrict the user from entering a tab in a text field using regular expression.

  • Is this field in a Lightning component, Visualforce page, a standard Salesforce page layout, or somewhere else? I think you can accomplish this in any of those scenarios, but the approach will be very different.
    – nbrown
    Apr 22, 2021 at 11:29

1 Answer 1

[ ]{2,}

It will check 2 or more spaces You could also check that before and after those spaces words follow. (not other whitespace like tabs or new lines)

\w[ ]{2,}\w

The same, but you can also pick (capture) only the spaces for tasks like replacement

\w([ ]{2,})\w

or see that before and after spaces there is anything, not only word characters (except whitespace)

[^\s]([ ]{2,})[^\s]

To be specific about Tab, you can use. It will check 1 or more that once tab

[ \t]{1,}

Not the answer you're looking for? Browse other questions tagged .