I have a text input box for entering user name. i want to restrict the special characters and numbers from being typed in that box(not showing the error after the submit button click. avoiding typing and pasting from keyboard and mouse). I came across some javascipt codes to restrict on the keyboard and mouse events (like keypress etc.,). but i think there might be better way than doing this by adding some html attributes or by adding some bootstrap framework classes.
I tried the below code (ruby on rails):
<%= f.text_field :fname, required: true, placeholder: "First Name", class: "form-control",:pattern => "^[a-zA-Z0-9]+$" %>
However this is triggering the error after submit button click
I am using JQuery in my application.