Hosting Solutions
mobile_logo Table of Contents

Restrict Text Input Characters HTML JavaScript Tutorial

Learn to restrict one or more text fields in a form to allow only characters that you desire to be typed into them. We will remove undesirable characters in real time as the user types.

<script> function lettersOnly(input) { var regex = /[^a-z]/gi; input.value = input.value.replace(regex, ""); } </script> <input id="firstname" placeholder="first name" onkeyup="lettersOnly(this)"> <input id="lastname" placeholder="last name" onkeyup="lettersOnly(this)">

Learn more about Regular Expression(RegExp) programming in JavaScript.


JavaScript Videos

Form Programming

Contact Form Web Application Tutorial Ajax HTML5 PHPCheckbox Toggle Tutorial Select Deselect All ElementsIn Place Editing CMS Development HTML JavaScript TutorialCustom Progress Bar Meter Development For File Upload FormsMultiphase Form Programming Tutorial Multi StepRestrict Text Input Characters HTML JavaScript TutorialMonthly Payment Loan Calculator Form Programming TutorialDynamic Select Year List Script HTML Form ElementsTip Calculator Application Form Programming Tutorialtextarea Form Field Character Counting and LimitingBuilding a WYSIWYG Rich Text Editor Textarea Replacement Part 1Building a WYSIWYG Rich Text Editor Textarea Replacement Part 2Div contenteditable Click Select All Text execCommand selectAllToggle Password Security Form Input Characters TutorialTrap User Check for Unsaved Written Work TutorialReal Time Text Input or Textarea Filter TutorialForm Select Change Dynamic List Option Elements Tutorial