如何输入强制性并从99或98开始 [英] How Do I Make Input Mandatory And Start With A 99 Or 98

查看:85
本文介绍了如何输入强制性并从99或98开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有下面的代码强制数字输入,但我如何确保有一些输入,并以98或99开头。



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

返回true;
}
//
- >

< / script >





表格为



  <  表格   方法  = 发布    action   =  insurance / >  
< span class = 输入输入 - fumi >
< input class = input__field input__field - fumi onkeypress = return isNumberKey(event) type = text maxlength = 11 id = < span class =code-keyword> input-25 / >
< label class = input__label input__label - fumi = input-25 >
< i class = fa fa-fw fa-credit-card图标图标 - fumi > < / i >
< span class = input__label- content input__label-content - fumi > 会员编号< / span >
< / label >
< / span >
< 按钮 type = 提交 class = btn-next > 下一步< / button >





预先感谢您的帮助

解决方案

HTML 5支持模式和数字类型:



 <  输入   类型  = 数字   名称  =  country_code    pattern   =  ^ [(99)(98)](\\ \\ n *)


title < span class =code-keyword> = 以99或98开头的数字 > < / input >





注意:Internet Explorer 9及更早版本或Safari中不支持输入标记的pattern属性。


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.

<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

<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

解决方案

HTML 5 supports pattern and number type:

<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.


这篇关于如何输入强制性并从99或98开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆