shahsank3t
shahsank3t

Reputation: 252

Regular expression to parse escape characters

I have a text field which accepts only one character but if user enters any escape characters such as \n, \t, \s, etc it should be allowing it even though it has 2 characters.

I am using jquery.validationEngine to validate the text field but failing to parse it as per my desire.

Upvotes: 1

Views: 132

Answers (1)

6502
6502

Reputation: 114491

A regular expression for that could be

[^\\]|\\[tns]

Meaning

  • any char except a backslash
  • or a backslash followed by t, n or s

Note that if you need to put this in a string literal then backslashes must be doubled again (doubled once for the string and doubled again to escape their special meaning in a regexp).

Upvotes: 1

Related Questions