Sunday, October 6, 2013

numeric input no dots or no hyphen android and iphone

<!DOCTYPE html>
<html>
<head>
<title>vivekmras.webhostingbuilders.com</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
 
</head>
<body>

<div  id="login">



    <label for="name">Login value:</label>
    <input type="text" name="name" id="name" value=""  />
   

           

    <label for="password">Password:</label>
    <input type="password" name="password" id="password" value="" />
   
   

   

           
 <button type="submit" data-theme="e" >Submit</button>

</div><!-- /content -->
        <script>
            function isNumberKey(evt){
                var mytextvalue = document.getElementById("passwrd").value;
               // alert("mytextvalue="+mytextvalue);
               //var str="myfile.doc";
               //alert(mytextvalue);
               if(mytextvalue.toString().indexOf('-') !== -1){
                   alert("value avialable");
               }
                var value =  evt.target.value;
               // alert("value="+value);
                if(mytextvalue==="1-"){
                    //alert("value="+mytextvalue);
                }
               
    var charCode = (evt.which) ? evt.which : event.keyCode;
     if(charCode === 45 || charCode === 46 ){
       // alert("1");
       //var string = "Hello";
        var str = mytextvalue.substring(0, mytextvalue.length);
        //alert(str);
      document.getElementById("passwrd").value=str;
      //alert("value="+value);
        return false;
     }
    if (charCode > 31 && (charCode < 48 || charCode > 57) && !(charCode === 45 || charCode === 46 )){
        //alert("charCode="+charCode);
        //evt.preventdefault();
        return false;
        //setTimeout(function(){},1);
    }else{
        return true;
       // evt.preventdefault();
    }

    }
   
 
        </script>
       
       
        <div  id="login1">
    <label for="password">Password:</label>
    <input type="number" id="passwrd" pattern="[0-9]*" onkeypress="return isNumberKey(event);"/>
   
 
        </div>

</body>


</html>

No comments:

Post a Comment