Click here to Skip to main content
15,884,956 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I currently have the code below which is forcing numerical input but how do i ensure there is some input and that is starts with a 98 or 99.

XML
<script>
<!--
       function isNumberKey(evt)
       {
          var charCode = (evt.which) ? evt.which : evt.keyCode;
          if (charCode != 46 && charCode > 31
            && (charCode < 48 || charCode > 57))
             return false;

          return true;
       }
       //-->
</script>


With the form being

XML
<form method="post" action="insurance/">
            <span class="input input--fumi">
                    <input class="input__field input__field--fumi" onkeypress="return isNumberKey(event)" type="text" maxlength="11" id="input-25" />
                    <label class="input__label input__label--fumi" for="input-25">
                        <i class="fa fa-fw fa-credit-card icon icon--fumi"></i>
                        <span class="input__label-content input__label-content--fumi">Membership Number</span>
                    </label>
                </span>
            <button type="submit" class="btn-next">Next</button>


Thanks in advance for your help
Posted

1 solution

HTML 5 supports pattern and number type:

HTML
<input type="number" name="country_code" pattern="^[(99)(98)](\d*)$" title="number starting with 99 or 98"></input>


Note: The pattern attribute of the input tag is not supported in Internet Explorer 9 and earlier versions, or in Safari.
 
Share this answer
 
v2
Comments
Richard Deeming 15-Sep-15 8:47am    
I think your pattern got messed up by the editor - there shouldn't be an <a> tag in there. :)
Andy Lanng 15-Sep-15 8:49am    
Thanks - Fixed ^_^

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900