2

User is allowed to enter all the alphabets and numbers but when the special-characters are entered then it shouldn't be entered in the the text box.

I tried doing this using (ng-pattern-restrict) but it's not working as expected, I think it might be possible that it needs to be imported in app-module.ts but not working.

HTML FILE

  • it is an AngularJS package – Akber Iqbal Mar 24 '19 at 02:59
  • I think rather than restricting user from entering special chars , won't it be good to let them type but invalidate the field & form ?? From user experience perspective, its better rather than disabling `keypress` events . Disabling special chars key press events might force the user to think that "my keyboard has broken keys" – Shashank Vivek Mar 24 '19 at 04:19
  • @ManirajfromKarur it's not duplicate of that query,@Shashankvivek what I'm asking is that I don't want user to let key press and input in the text area instead of showing some error or warning to him. –  Mar 25 '19 at 05:34

1 Answers1

0

@Shashank has a valid point of view. What you want to do is disable the entry of special characters from the backend, as well as render the field invalid from the frontend. A hacker knowing what they're doing would easily manipulate the HTTP Request itself rather than the field, making it pretty vulnerable.

However, if you insist on your solution, I would recommend using RegEx. This sample expression might come in handy. That way, whenever the input field detects one of these special characters, it would replace that character with a ''

TheLebDev
  • 531
  • 6
  • 18
  • BTW Thanks Chris for a good suggestion, I really appreciate your approach towards my query. :) –  Mar 27 '19 at 08:56