Reputation: 3
My textbox should accept only special characters only once. for example: It should not allow '%' symbol more than once. All the special characters should be allowed only once in my textbox in JS. I tried so many answers in stackoverflow but failed to get the exact code. 'Like so'
`/^(?=[a-zA-Z,]*['.-][a-zA-Z,]*$)[a-zA-Z,'.-]+$/`
Here instead of apostrophe, dash and period , I tried '%' but its allowing as many Percentages (%) as can.
Upvotes: 0
Views: 1141
Reputation: 19571
Write an event handler that catches keypresses on your textarea. Have it check event.which
against the characters in the textarea. If it isn't allowed, return false or call event.preventDefault() and the character will not be inputted.
Upvotes: 1