String must be certain length

Hi guys

How can I check that my string is a certain length

Here is my code

    
                var inpObjs = document.getElementsByName('licensenumber[]');
                validChars = /^[a-zA-Z\\d]/
                for(i=0; i < inpObjs.length; i++){
                    if(!validChars.test(inpObjs[i].value)){

if (inpObjs.length() != 16) 
                      alert("Please enter licence number for each person");
     return false;
                    }
                }
               

I have a better regular expression: /[1]{16}$/
\d - matches a digit
$ - matches the end of the string
{16} - means 16 occurrences
Try the following code:


validChars=/^[a-zA-Z\\d]{16}$/;
                for(i=0; i < inpObjs.length; i++){
                    if(!validChars.test(inpObjs[i].value)){
                       alert("Please enter licence number for each person");
                       return false;
                    }
                }

Notes:
inpObj.length is the size of the array retruned by “getElementsByName”
inpObj[i] is the i’th elementh of the array inpObj.


  1. a-zA-Z\d ↩︎

Thank you very much