How to add pattern and title in input

Viewed 297

Hi all I have following code:

   <form>
       <input type="text" id="FormField_6_input"  name="CompanyName"/>
       <button id="ContinueButton_6">Continue</button>
   </form> 
   <script>
    let companyNameField = document.getElementById('FormField_6_input');
    companyNameField.setAttribute("pattern", "/[2-9]{1}\d{3}/");
    companyNameField.setAttribute("title", "invalid input");
   </script>

I want to add pattern and title attributes to my input but it not working please help me to resolve this problem.

1 Answers

I edited your code please review.

 
    let companyNameField = document.getElementById('FormField_6_input');
    companyNameField.setAttribute("pattern", "[2-9]\\d{3}" );
    companyNameField.setAttribute("title", "invalid input");
 <form>
       <input type="text" id="FormField_6_input"  name="CompanyName"/>
       <button id="ContinueButton_6">Continue</button>
   </form> 

Related