【问题标题】:Validate field to indian mobile number验证印度手机号码的字段
【发布时间】:2017-03-05 20:51:12
【问题描述】:

我的输入字段应该只有 10 位数字,其中包含 0-9 数字,以及开头的选项 +91 或 0。所以我必须将我的输入字段限制为 13 个数字,包括可选的 +91。

这个字段应该只接受数字,这是我所做的,但它未能验证如果有任何更改,请建议我。我需要使用 html-5 正则表达式进行验证。

<input type="text" maxlength="13" pattern="\ *\+?\d+"  required 
name="" title="Only numbers and '+' are accepted" id="" class="register-input-val form-control input-lg" placeholder=" Mobile Number" >

这是我的 JSFIDDLEDEMO

The number format will look like this
+91XXXXXXXXXX +91 and 10 digits
0XXXXXXXXXX 10 digits with 0

【问题讨论】:

标签: jquery html validation


【解决方案1】:

如果您更喜欢使用正则表达式进行验证。

((\+*)((0[ -]+)*|(91 )*)(\d{12}|\d{10}))|\d{5}([- ]*)\d{6}

the fiddle here

body {
    padding: 10px;
    font-family: Arial;
    Font-size: 10pt;
}
span {
    font-weight:bold;
}
<form action="">
  <input type="text" maxlength="13" pattern="((\+*)((0[ -]+)*|(91 )*)(\d{12}+|\d{10}+))|\d{5}([- ]*)\d{6}"  required 
name="" title="Only numbers and '+' are accepted" id="" class="register-input-val form-control input-lg" placeholder=" Mobile Number" >
<button type="submit">Validate</button>  
</form>
                

【讨论】:

【解决方案2】:

你可以使用正则表达式

((+*)((0[ -]+)|(91 ))(\d{12}+|\d{10}+))|\d{5} ([- ]*)\d{6}

希望它有效...

【讨论】:

  • 我需要它包含在 HTML-5 的模式中
  • 电话:
【解决方案3】:

请查看此答案。 (即Regular Expression Validation For Indian Phone Number and Mobile number

如果您对此有任何疑问,请告诉我。

【讨论】:

  • 我需要将它包含在 HTML-5 的模式中
【解决方案4】:

你可以使用它。

((+91)|0){1}(\d{10})

【讨论】:

    【解决方案5】:

    将此“^((+91[0-9]{10})|(0[0-9]{10}))$”添加到您输入的属性模式中

    <form method="post">
      <input type="text" maxlength="13" pattern="^((\+91[0-9]{10})|(0[0-9]{10}))$"  required 
      name="" title="Only numbers and '+' are accepted" id="" class="register-input-val form-control input-lg" placeholder=" Mobile Number" >
      <input type="submit">
    </form>
    

    DEMO

    【讨论】:

      猜你喜欢
      • 2018-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-23
      • 1970-01-01
      • 2013-04-14
      • 2017-02-06
      • 1970-01-01
      相关资源
      最近更新 更多