验证字段为印度手机号码 [英] Validate field to indian mobile number

查看:72
本文介绍了验证字段为印度手机号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个输入字段,除了只能包含10-9个数字(其中包含0-9个数字)和开头的选项+91或0之外.因此,我必须将输入字段限制为13个数字,其中包括+91(可选).

I have input field that should except only 10 digits which contain 0-9 numbers, and a option +91 or 0 at the start. SO i have to restrict my input field to 13 number including +91 as optional.

此字段仅应接受数字,这是我所做的,但无法验证,请建议我是否有任何更改.我需要使用html-5语法表达式进行验证.

This field should only accept numbers here is what I have done but its failing to validate please suggest me if any changes. I need to validate using html-5 reghular expression.

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

这是我的JSFIDDLE 演示

Here is my JSFIDDLEDEMO

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

推荐答案

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

If you'll prefer using regular expression to validate.

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

请参见此处的小提琴

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>
                

这篇关于验证字段为印度手机号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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