Search code examples
javascriptnumbersletters

How to check for numbers in a textbox, of which you only want letters A - Z


I am using JavaScript on my website to check input elements within a form. I am trying to ensure that there are no numbers in the field when the user enters their name. The form is created using PHP. I am still in my first year of web design so not sure if there is a function for this. Apologies if this question has been asked, but I haven't found anything. Many Thanks


Solution

  • if you are targetting html5 browser you can use the pattern attribute

    <input type="text"  pattern="^[a-zA-Z]*$" >