samedi 26 novembre 2016

RegExp incorrectly invalidate user unput

Already spent 2 days on this very basic regex .I want it to validate inputs exactly of 4 characters.And only upper & lower case Letters.No digits or special symbols.But it is invalidating everything including the correct ones. Can't catch the issue. Please help.Code below:---

thanks

pkj

<!DOCTYPE html>

<HTML><HEAD>
<TITLE>
 RegEx Test
</TITLE>
</HEAD>
<BODY>
     <P>
        <FORM action="cgi-bin/page2.py"
           Type something:<input  Id="usrInput" TYPE="text" VALUE="" onblur="chkInput()">
                  <input Id="ts" TYPE="number" NAME="ts" value=0> 
                  <input id="submit" type="submit" value="Go" >
        </FORM>
    </P>
     <script>
        function chkInput(){
         var myRgx=new RegExp(/^[a-zA-Z]{4}$/);   
         var input=document.getElementById("usrInput").innerHTML;  
          var rslt=myRgx.test(input);
          alert(rslt)
        }

     </script>
</BODY>

Aucun commentaire:

Enregistrer un commentaire