I use javascript regex to do some data validation and specify the characters that I want to accept (I want to accept any alphanumeric characters, spaces and the following !&,'\-
and maybe a few more that I will add later, If you want to). My code is:
var value = userInput; var pattern = /[^A-z0-9 "!&,'\-]/; if(patt.test(value) == true) then do something
It works great and excludes letters that I donβt want to enter to the user, except for square brackets and carriage characters. Of all the javascript regular expression tutorials I read, they are special characters - brackets mean any character between them and the carriage in this instance, meaning any character not between the square brackets. I searched here and on Google for an explanation of why these characters are also accepted, but cannot find an explanation.
So can someone help why my input accepts square brackets and a carriage?
David source share