I am having an issue with a field that is supposed to accept all characters and digits, including English and Arabic, but not special characters like
~!@#$%&*.()[]{}<>^+=:,;?/\'
Specifically, only special characters will be considered as incorrect.
Below is the code I have written,
var textToMatch='$a$';
var pattern = /[^~!@#$%&*\[\]\{\}\<\>\^+=:,;?/\\]+$/
var validationResult = pattern.test(textToMatch);
This code works fine when I enter "$$@" or "a$" in the textToMatch variable (result: (false)invalid as expected). Note: it only works when the last character is a special character
However, it fails when I enter any non-special character as the last character in the textToMatch variable (result: (true) valid which is unexpected), for example: "$a".
I am really stuck here. Any help would be greatly appreciated.